I am using a nested form ( User has_one Account .. to hold profile data) to UPDATE my user/account data User model has_one :account accepts_nested_attributes_for :account, :allow_destroy => true Account model belongs_to :user ------- my form seems to work fine, I can see in the console, the @user attributes and the account attribute in the hash .... "password"=>"", account"=>{"city"=>"", "zip"=>"", "country"=>"BE", "street_address"=>"", ...}... when I debug in the console, @user.attributes = params[:user] @user.valid? => true # OK no errors @user.attributes = params[:account] @account.valid? => false # OK , name is blank... but if I debug my :edit action, if @user.update_attributes(params[:user]) I get true..... which seems to mean that the account errors are not tracked ? according to the doc it should be false ... where am I wrong ? additional Question : when errors , how should I display the them when they are related to the user.account should I use @user and @account and : error_message_on @account, :first_name, or only @user and error_message_on @user.account, :first_name, thanks for your recommandations erwin
The account data must be in :user => {:account_attributes => {...}} if you want auto save it. You can read about it in the documentation of ActiveRecord::NestedAttributes::ClassMethods (see fields_for in ActionView::Helpers::FormHelper too). Regards. Franco Catena. On Jul 1, 1:22 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> I am using a nested form ( User has_one Account .. to hold profile > data) to UPDATE my user/account data > > User model > has_one :account > accepts_nested_attributes_for :account, :allow_destroy => true > > Account model > belongs_to :user > > ------- > my form seems to work fine, I can see in the console, the @user > attributes and the account attribute in the hash > .... "password"=>"", account"=>{"city"=>"", "zip"=>"", > "country"=>"BE", "street_address"=>"", ...}... > > when I debug in the console, > @user.attributes = params[:user] > @user.valid? => true # OK no errors > @user.attributes = params[:account] > @account.valid? => false # OK , name is blank... > > but if I debug my :edit action, > if @user.update_attributes(params[:user]) > I get true..... which seems to mean that the account errors are not > tracked ? according to the doc it should be false ... > > where am I wrong ? > > additional Question : when errors , how should I display the them > when they are related to the user.account > should I use @user and @account and : > error_message_on @account, :first_name, > > or only @user and > error_message_on @user.account, :first_name, > > thanks for your recommandations > > erwin
thanks Franco, .. I was hitching my head and just discover in the log : WARNING: Can''t mass-assign these protected attributes: account so this attribute was wrong... and you gave me the answer !! On 1 juil, 18:56, Franco Catena <francocat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The account data must be in :user => {:account_attributes => {...}} if > you want auto save it. > > You can read about it in the documentation of > ActiveRecord::NestedAttributes::ClassMethods (see fields_for in > ActionView::Helpers::FormHelper too). > > Regards. > > Franco Catena. > > On Jul 1, 1:22 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > I am using a nested form ( User has_one Account .. to hold profile > > data) to UPDATE my user/account data > > > User model > > has_one :account > > accepts_nested_attributes_for :account, :allow_destroy => true > > > Account model > > belongs_to :user > > > ------- > > my form seems to work fine, I can see in the console, the @user > > attributes and the account attribute in the hash > > .... "password"=>"", account"=>{"city"=>"", "zip"=>"", > > "country"=>"BE", "street_address"=>"", ...}... > > > when I debug in the console, > > @user.attributes = params[:user] > > @user.valid? => true # OK no errors > > @user.attributes = params[:account] > > @account.valid? => false # OK , name is blank... > > > but if I debug my :edit action, > > if @user.update_attributes(params[:user]) > > I get true..... which seems to mean that the account errors are not > > tracked ? according to the doc it should be false ... > > > where am I wrong ? > > > additional Question : when errors , how should I display the them > > when they are related to the user.account > > should I use @user and @account and : > > error_message_on @account, :first_name, > > > or only @user and > > error_message_on @user.account, :first_name, > > > thanks for your recommandations > > > erwin
Can someone please point me in the right direction on what to do here, in terms of basic architecture. I;ve seen this type of interface before. Let''s say I have something that is "sold" and I have a form for the sold information. At the bottom of the form, say, us a little "plus sign" or something like that, with a notation after it that says "Customer", which then opens up another form, embedded in the sold form (in terms of the UI) to enter possible customer information for a second form, and that customer form may have another form embedded in it with a plus sign, etc. When I submit on an embedded form, it closes, taking me to its enclosing form, with a plus sign where the one I just submitted was. The basic idea therefore is to 1. conserve screen space 2. not require you to redirect to another page for a form which is linked to by it;s enclosing form Is there a standard library for this type of thing? (Im open to any ideas that satisfy these two points mentioned) If not, can you tell me how to create it? Thanks, Janna B
On Sat, 2009-07-11 at 17:55 -0700, JannaB wrote:> Can someone please point me in the right direction on what to do here, > in terms of basic architecture. I;ve seen this type of interface > before.The short answer is that you cannot nest forms structurally. The standard prohibits. What you can do, and is easy to do if you learn a little CSS, is to nest them visually. Those are two completely separate issues. Best reagards, Bill
Hello-- On Jul 11, 2009, at 5:55 PM, JannaB wrote:> > Can someone please point me in the right direction on what to do here, > in terms of basic architecture. I;ve seen this type of interface > before. > > Let''s say I have something that is "sold" and I have a form for the > sold information. At the bottom of the form, say, us a little "plus > sign" or something like that, with a notation after it that says > "Customer", which then opens up another form, embedded in the sold > form (in terms of the UI) to enter possible customer information for a > second form, and that customer form may have another form embedded in > it with a plus sign, etc. When I submit on an embedded form, it > closes, taking me to its enclosing form, with a plus sign where the > one I just submitted was. > > The basic idea therefore is to > 1. conserve screen space > 2. not require you to redirect to another page for a form which is > linked to by it;s enclosing form > > Is there a standard library for this type of thing? (Im open to any > ideas that satisfy these two points mentioned) If not, can you tell me > how to create it? Thanks, Janna Bhttp://railscasts.com/episodes/73-complex-forms-part-1
Im ok with the controller / model architecture....it;s the UI itself that I am trying to accomplish. Simply, a means to collapse forms on the screen is reallyt what I want. Thanks! Janna
http://www.prototypejs.org/api/element/toggle $(''your-sub-form'').toggle() will hide or show a given element. Just wrap your subform in a div with a unique id and put a disclose link outside that div. You can then use an onclick handler for that disclose link if you like the inline JS route or by defining the behavior of the element in the document.observe(''''dom:loaded", ...) function. hth On Jul 11, 2009, at 7:14 PM, JannaB wrote:> > Im ok with the controller / model architecture....it;s the UI itself > that I am trying to accomplish. Simply, a means to collapse forms on > the screen is reallyt what I want. Thanks! Janna > >