我有一个表单,我的用户可以选择一个日期和一个地点来创建新的预订。
每个预订可以有几个景点。如何在创建表单中添加多个隐藏项目
class Reservation < ActiveRecord::Base
has_many :spotations
has_many :spots, :through => :spotations
end
class Spotation < ActiveRecord::Base
belongs_to :reservation
belongs_to :spot
end
class Spot < ActiveRecord::Base
has_many :spotations
has_many :reservations, :through => :spotations
end
现在我给我的用户一个select_list来选择一个点。 只有可用斑点显示在该列表中。 (只有当天没有为该物品预订的景点)
<%= f.collection_select :spot_ids, @availablespots, :id, :name, {:prompt => true}, {class: "form-control spot_selection", id:"reservation_spot_ids", name:"reservation[spot_ids]", required:"required" } %>
一切正常。
但我让我的模型接受几个景点: 我想预订用户选择的地点和之前的地点自动(旅行时间)。
我不知道如何在我的控制器中做到这一点。
我所有的景点都是按照id排序的。 (1到20),如果用户选择可用的点id = 4,我也想预订id = 3。
有人有想法吗? 谢谢,
在创建操作中,您可以找到现场n-1并将其添加到模型中。 – phoet 2014-10-11 22:14:41
Thx您的回复。一旦将它发送到创建过程,我如何访问我的:spot_ids params(散列)? (为了得到n-1),然后我怎么把这个点(我找到的n-1)放回到创建过程中呢? – Devlesch 2014-10-11 23:07:04