Reputation: 119
I am creating a flight booker in Rails and I'm having trouble showing my flight information for eligible flights on rails. The user can select to and from airports, passengers, and a date for the flight. If the flight exists it displays the information. But my flight isn't displaying.
index.html form to display the flights
<p>
<% unless @eligible_flights.empty? %>
<% @eligible_flights.each do |f| %>
<%= f.start_airport_id %>
<% end %>
<% else %>
<%= "No Flights Found" %>
<% end %>
</p>
flights controller to view
def index
@flights = Flight.all
@eligible_flights = Flight.where("start_airport_id = ? AND end_airport_id = ? AND departure_time = ?",
params[:start_airport],
params[:end_airport],
params[:departure_time])
end
Upvotes: 0
Views: 50
Reputation: 14890
My best guess is that the date comparison is not working correctly, you should try implementing your query the Rails way with.
@eligible_flights = Flight
.where(start_airport_id: params[:start_airport])
.where(end_airport_id: params[:end_airport])
.where(departure_time: params[:departure_time])
Upvotes: 1