Hi,
Im having an issue with accepts_nested_attributes_for for a has_one
relationship. I have posted the code below and the parameters sent to
the create but this is not saving the user_detail association record.
Ive tried various solutions from the links below but cant get this to
work.
Can anyone suggest what im doing wrong?
class User < ActiveRecord::Base
has_one :user_detail, :dependent => :destroy
accepts_nested_attributes_for :user_detail
attr_accessible :first_name, :user_detail_attributes
end
def new
@user = User.new
#@user.build_user_detail
end
- form_for([:members, @user]) do |user_form|
= user_form.label ‘first_name’, ‘First Name’
= user_form.text_field :first_name
[email protected]_user_detail unless @user.user_detail
-user_form.fields_for :user_detail do |ud_form|
%li
= ud_form.label ‘website_url’
= ud_form.text_field :website_url
“user”=>{“user_detail_attributes”=>{“website_url”=>“www.bbc.co.uk”},
“commit”=>“Sign up”}
http://www.pixellatedvisions.com/2009/03/18/rails-2-3-nested-model-forms-and-nil-new-record
http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
I also tried replacing -user_form.fields_for :user_detail do |ud_form|
with
-user_form.fields_for @user.user_detail do |ud_form| but then i got
UserDetail(#48943070) expected, got HashWithIndifferentAccess(#23663900)
JB