bob
2010-Jan-24 21:11 UTC
Nothing shows up under fields_for when referring to a valid association
Hi, I have something like this: class Group < ActiveRecord::Base has_many :members accepts_nested_attributes_for :members end class Member < ActiveRecord::Base belongs_to :group end -form_for @group do |form| -form.fields_for :members do |member| =member.text_field :display_name and nothing shows up under "form.fields_for :members do |member|". In fact, if I put invalid code there, it''s not even evaluated. However, if I specify an invalid assocation like "form.fields_for :memberszzzz do |member|", the text field for :display_name does show up. Does anyone know what could be problem? Thanks! Bob -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bob
2010-Jan-24 22:48 UTC
Re: Nothing shows up under fields_for when referring to a valid association
Ok, it turns out the problem was that I needed to specify attr_accessible :members_attributes in the model, and @group.members.build in the controller for it to work. Found the solution here: http://stream.btucker.org/post/93887650/accepts-nested-attributes-for-fields-for On Jan 24, 1:11 pm, bob <papersm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have something like this: > > class Group < ActiveRecord::Base > has_many :members > accepts_nested_attributes_for :members > end > > class Member < ActiveRecord::Base > belongs_to :group > end > > -form_for @group do |form| > -form.fields_for :members do |member| > =member.text_field :display_name > > and nothing shows up under "form.fields_for :members do |member|". In > fact, if I put invalid code there, it''s not even evaluated. However, > if I specify an invalid assocation like "form.fields_for :memberszzzz > do |member|", the text field for :display_name does show up. > > Does anyone know what could be problem? > > Thanks! > > Bob-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.