Now I have another problem, How can I get the values from database to
show in the fields for edit action ?
Asking a question so vague - how can I get values from database - is
very difficult to answer. Please give more details of what you are
trying to do.
Since this seems fairly basic stuff have you worked through the Rails
Guides and some tutorials? railstutorial.org is good and free to use
online.
I have 3 tables/models products, colors, stock, the problem is I need
to save product with N colors and each color I need to tell what the
quantity each color.
class Stock < ActiveRecord::Base
belongs_to :product
belongs_to :color
end
Color Model
class Color < ActiveRecord::Base
has_many :stocks
has_many :product, :through => :stocks
end
From view _form.erb
Just the associations:
<%= fields_for :stocks do |stock_form| %>
<% for color in Color.all %>
<%= stock_form.check_box :color_id %> <%= color.name %>
<%= stock_form.text_field :qtd %>
<% end %>
<% end %>