build_* not working despite being has_one
My intention here is just to create a correspo开发者_Go百科nding 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.
Does it work if you pass the attributes to build
?
contact = @user.build_contact(:contactable => School.first)
contact.save
精彩评论