I'm quite new to rails and I have some problem with views...
I have among others these three models : reservation,route and stop.
When you make a reservation, you have to select the route and the city of departure/arrival.
EDIT
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
I don't know if it is possible but I'd like to be able to select my city of departure/arrival only among those that belong to the route I've chosen. Any ideas how to do that?
Thank you!
Below there's a part of my reservation's form:
<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>