views:

56

answers:

1

Hey all,

My intention here is just to create a corresponding contact when a user signs up, but the said contact is never created, despite using build_* with a has_one:

Contact model:

has_one :user

User model:

belongs_to :contact

Users Controller:

def signup
  @user = User.new
end

def signup_success
 @user = User.find params[:id]
 contact = @user.build_contact
 contact.contactable = School.first
 contact.save
end

protected

routes:

map.resources :users,
:collection => {
  :signup => :get
},
:member => {
  :signup_success => :any
}

Any idea of what I'm doing wrong? Thanks for any suggestions.

A: 

Does it work if you pass the attributes to build?

contact = @user.build_contact(:contactable => School.first)  
contact.save
John Topley
No. Even when I add it directly to the model, it still doesn't work:before_create :ensure_site def ensure_site if :signup contact = self.build_contact(:contactable => School.first) contact.save end end
JohnMerlino
The issue was when I save a contact, it was invoking a validate from the contacts page which was preventing the saving. Thanks though. I like your parameter hash technique better than the multi-step way I was doing it.
JohnMerlino
Glad you were able to get it working.
John Topley