我对 Rails 很陌生,我对视图有一些问题......
我有这三种模型:预订、路线和停止。
预订时,您必须选择路线和出发/到达城市。
编辑
class Route < ActiveRecord::Base
has_many :stops, :dependent => :destroy
has_many :reservations, :dependent => :destroy
belongs_to :train
end.
class Stop < ActiveRecord::Base
belongs_to :route
has_many :reservation_deps, class_name: "Reservation", foreign_key: "dep_city_id"
has_many :reservation_arrs, class_name: "Reservation", foreign_key: "arr_city_id"
end
class Reservation < ActiveRecord::Base
belongs_to :user
belongs_to :route
belongs_to :arr_city, class_name: "Stop",foreign_key: "arr_city_id"
belongs_to :dep_city, class_name: "Stop",foreign_key: "dep_city_id"
end
我不知道这是否可能,但我希望能够仅在属于我选择的路线的城市中选择我的出发/到达城市。任何想法如何做到这一点?
谢谢!
下面是我的预订表格的一部分:
<div class="field">
<%= f.label :route %><br>
<%= f.collection_select(:route_id,Route.all,:id,:as_field) %><br>
</div>
<div class="field">
<%= f.label :departure_city %><br>
<%= f.collection_select(:dep_city_id,Stop.all,:id,:city) %><br>
</div>
<div class="field">
<%= f.label :arrival_city %><br>
<%= f.collection_select(:arr_city_id,Stop.all,:id,:city) %><br>
</div>