ruby on rails - Nested Form and database update -
i'm quite new rails, question may seem noobish.
i have habtm self association. product can become "combo" of products, having n products.
class product < activerecord::base has_many :combo_elements, class_name: "comboelement", foreign_key: :combo_id has_many :element_combos, class_name: "comboelement", foreign_key: :element_id has_many :combos, :through => :element_combos has_many :elements, :through => :combo_elements accepts_nested_attributes_for :elements end class comboelement < activerecord::base belongs_to :combo, :class_name => 'product' belongs_to :element, :class_name => 'product' end
with above code, can list "elements" of combo. can list "combos" product part of (the comboelement table has combo_id , element_id)
here form
<%= f.simple_fields_for :elements, @element |b| %> <%= b.input :element_id, :collection => product.all.collect{ |t| [t.name, t.id ]}, selected: b.object.id %> <%= b.link_to_remove "remove element" %> <% end %>
i can list products combo has, whenever try update, doesn't work.
my product controller has following code
def product_params params[:product].permit(:name, :price, elements_attributes: [:id, :element_id, :_destroy]) end
i appreciate help. in advance!
Comments
Post a Comment