Now I have another problem, How can I get the values from database to show in the fields for edit action ?
Any one can help me ? On 12 out, 08:55, Farah <[email protected]> wrote: > People I figure out this problem > > The problem was solved with this > > # models/product.rb > accepts_nested_attributes_for :stocks > > # views/product/_form.erb > > <% for color in Color.all %> > <div> > <%= check_box_tag > "product[stocks_attributes][][color_id]", > color.id, @product.colors.include?(color) %> > <%= color.name %> > <%= text_field_tag > "product[stocks_attributes][][qtd]" %> > </div> > <% end %> > > On 11 out, 23:35, Farah <[email protected]> wrote: > > > > > > > > > Please how can I save more than one field ? > > > I have Product has many colors by quantity. > > > This works > > #controller: products action: new file:_form.erb > > <% for color in Color.all %> > > <div> > > <%= check_box_tag "product[color_ids][]", > > color.id, > > @product.colors.include?(color) %> > > <%= color.name %> > > </div> > > <% end %> > > > but if I add one more field the value will not work. > > > <%= text_field_tag "stock["+color.id.to_s+"][qtd]" %> > > > Please anyone can help me? > > > My structure: > > > class Product < ActiveRecord::Base > > has_many :stocks, :dependent => :destroy > > has_many :colors, :through => :stocks > > end > > > class Color < ActiveRecord::Base > > has_many :stocks > > has_many :product, :through => :stocks > > end > > > class Stock < ActiveRecord::Base > > belongs_to :product > > belongs_to :color > > end -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

