我有一个MenuPizza模型连接到ToppingsModel的连接表:
class MenuPizza < ActiveRecord::Base
has_many :pizza_toppings
has_many :toppings, through: :pizza_toppings
end
class PizzaTopping < ActiveRecord::Base
belongs_to :menu_pizza
belongs_to :topping
end
class Topping < ActiveRecord::Base
has_many :menu_pizzas, through: :pizza_toppings
has_many :pizza_toppings, inverse_of: :topping
end
当用户创建新的MenuPizza时,他们应该能够从包含数据库中已有的所有浇头的下拉列表中选择一个浇头。他们应该能够为多个浇头做到这一点。
= form_for @menu_pizza do |f|
- if @menu_pizza.errors.any?
#error_explanation
%h2 = pluralize(@menu_pizza.errors.count, 'error') prohibted this post from being saved
.field
= f.label :name
= f.text_area :name
= f.label :description
= f.text_area :description
= f.select(:topping_ids, @toppings)
= f.submit 'Add Toppings', name: 'add-toppings'
我的问题是,如何提交对配料的多个参考?我试过了:
= f.select(:topping_ids, @toppings)
= f.select(:topping_ids, @toppings)
但是只提交了最后选择的顶部。