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
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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.