Ruby 你有过很多经历吗

Ruby 你有过很多经历吗,ruby,forms,ruby-on-rails-4,has-many-through,has-and-belongs-to-many,Ruby,Forms,Ruby On Rails 4,Has Many Through,Has And Belongs To Many,我希望在构建一个“通过关系”的表单方面能得到一些帮助 我有三门课: 订单.rb has_many :selections has_many :items, :through =>:selections; has_many :selections has_many :orders, :through => :selections belongs_to :order belongs_to :item item.rb has_many :selections has_many :it

我希望在构建一个“通过关系”的表单方面能得到一些帮助

我有三门课:

订单.rb

has_many :selections
has_many :items, :through =>:selections;
has_many :selections
has_many :orders, :through => :selections
belongs_to :order
belongs_to :item
item.rb

has_many :selections
has_many :items, :through =>:selections;
has_many :selections
has_many :orders, :through => :selections
belongs_to :order
belongs_to :item
selection.rb

has_many :selections
has_many :items, :through =>:selections;
has_many :selections
has_many :orders, :through => :selections
belongs_to :order
belongs_to :item
Selections上有一个额外属性,用于捕获所选项目的数量

我试图做的是创建一个表单,允许用户选中一个框,指示他们想要的项目类型并提供数量

_X_ Food1 _6_
___ Food2 __
_X_ Food3 _1_
我的问题是,我不知道如何命名表单元素,以便它们进入控制器。我不能用

<%= collection_check_boxes(:order, :item_ids, @course.items.all, :id, :name, {:item_wrapper_class => 'checkbox_container'}) %>
'checkbox\u container'})%>
因为这将只打印带有复选框的食物,我需要捕获每个选定项目的数量


我需要帮助的是如何创建_form.html.erb以及控制器中可能需要的特殊gotcha

首先,item.rb应为

has_many :selections
has_many :orders, :through => :selections

其次,为什么要使用复选框?如果为空,为什么不将默认值设置为零或零?也就是说,如果您有多个,您可以将其用作真实值,以代替正在检查或未检查的支票。

感谢您捕获该项目的输入错误。你建议我只做Food1[2]Food2[]Food3[4]这肯定是一个更好的方法,但我仍然不确定如何构造表单,以便控制器正确填充选择。你能进一步说明你想做什么吗?