I have a User model class User < ActiveRecord::Base has_one :account accepts_nested_attributes_for :account, :allow_destroy => true validates_associated :account attr_accessible :account_attributes is working fine, validating and updating both records (User and Account), but I caanot display the value in the form when is updated, ex: below the firstname is not displayed but it''s in the db account record #<User id: 1, email: "yves-oHC15RC7JGRl57MIdRCFDg@public.gmane.org", .. #<Account id: 4, user_id: 1, title: 0, first_name: "Yves", ... my view ... <% form_for :user, :url => { :action => "update" } do |user_form| %> <% user_form.fields_for :account_attributes do |account_fields| %> <li> <label for="user_firstname">First Name</label> <%= account_fields.text_field :first_name, :size => "30" %> </li> ..... what am I missing ? thanks for your help erwin
Discover the issue : I had to write correctly my form_for <% form_for :user, @user, ... and not <% form_for :user Oops On 2 juil, 00:04, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> I have a User model > > class User < ActiveRecord::Base > has_one :account > accepts_nested_attributes_for :account, :allow_destroy => true > validates_associated :account > attr_accessible :account_attributes > > is working fine, validating and updating both records (User and > Account), but I caanot display the value in the form when is updated, > ex: below the firstname is not displayed but it''s in the db account > record > #<User id: 1, email: "y...-oHC15RC7JGRl57MIdRCFDg@public.gmane.org", .. > #<Account id: 4, user_id: 1, title: 0, first_name: "Yves", ... > > my view > ... > <% form_for :user, :url => { :action => "update" } do |user_form| > %> > <% user_form.fields_for :account_attributes do |account_fields| %> > > <li> > <label for="user_firstname">First Name</label> > <%= account_fields.text_field :first_name, :size => "30" %> > </li> > ..... > > what am I missing ? > > thanks for your help > > erwin
Kad Kerforn
2009-Jul-01 23:18 UTC
Re: Nested Forms - how to displayed the attributes content ?
> ... > <% form_for :user, :url => { :action => "update" } do |user_form| > %>WRONG need to be : form_for :user, @user, :url => { :action => "update" } do |user_form| Ooops ! -- Posted via http://www.ruby-forum.com/.