9 Aug 2012 17:25
Nested form with has_many :through -- how to modify the "through" attributes
This question occurred to me as I was answering a different question. Given a has_many :through relationship, where there are additional attributes in the :through model, how would you construct a form so you could update those attributes? #foo.rb class Foo < ActiveRecord::Base has_many :bars has_many :bazzes, :through => :bars accepts_nested_attributes_for :bazzes end #bar.rb class Bar < ActiveRecord::Base belongs_to :foo belongs_to :baz # also defines the 'blarg' attribute end #baz.rb class Baz < ActiveRecord::Base has_many :bars has_many :foos, :through => :bars end So in a form_for <at> foo, in fields_for :bazzes, how would I define a checkbox to set the 'blarg' attribute to true or false? Does the nested <at> foo.baz just have a magical #blarg attribute, even though that attribute is defined in the linking model Bar? Thanks, Walter -- -- 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@... To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@... For more options, visit https://groups.google.com/groups/opt_out.
RSS Feed