0

我有一个嵌套表,称为 products 嵌套在party 表下,其中一个comluns 是“brand”。产品有数量、颜色和“品牌”。对于“品牌”,我希望用户能够对用户想要的每个产品的多个品牌进行多项选择和收集。我该怎么做?我安装了“rails selected gem”,但似乎我需要分配更多。

表中的一列是否有可能为每个用户和产品提供多个集合?看来我应该使用索引?

代码:

Product.rb:
class Product < ActiveRecord::Base
attr_accessible :party_id, :party, :id, :brand, :color, :name, :quantity
belongs_to :party
BRAND_TYPES = ["Hugs", "Kisses", "Love" ]
end

Party.rb:
class Party < ActiveRecord::Base
validates :user_id, presence: true
attr_accessible :name, :products_attributes, :products, :user_id
belongs_to :user
has_many :products
accepts_nested_attributes_for :products, allow_destroy: true
end

_product_fields.html.erb:
<table>

<tr> 
<td> <%= f.label :name, "Product Name" %> </td>
<td> <%= f.text_field :name %> </td>
<td> <%= f.label :color, "Color" %> </td>
<td> <%= f.text_field :color %> </td>
<td> <%= f.label :Quantity, "Quantity" %> </td>
<td> <%= f.text_field :quantity %> </td>
<td> <%= f.label :brand, "Brand" %> </td>
<td> <%= f.select :brand, Product::BRAND_TYPES, :multiple => true %> </td>
<td> <%= f.link_to_remove "Remove this task" %></td>



</tr>
</table>

谢谢,我很感激。

4

0 回答 0