【发布时间】:2016-10-26 07:48:12
【问题描述】:
我需要在多对多连接表中设置一个自定义字段。目前我只能设置与复选框的关系,但我还需要设置一个数量字段。
我的模型:
class Quote < ApplicationRecord
has_and_belongs_to_many :options, :join_table => :quotes_options
accepts_nested_attributes_for :options, :allow_destroy => true
end
class Option < ApplicationRecord
has_and_belongs_to_many :quotes
end
和形式:
form do |form|
form.inputs do
form.input :options, :as => :check_boxes,:collection => Option.all
end
end
所以现在它呈现为复选框列表,如
New Quote
[X] First option
[ ] Second option
问题是在表 ":join_table => :quotes_options" 我也有字段 ":quantity" 所以我也想更新它。所以我的观点是这样的,我将能够在联合表中保存数量
New Quote
[X] First option [ ] quantity
[ ] Second option [ ] quantity
【问题讨论】:
标签: ruby-on-rails activeadmin formtastic