0

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
2
  • So, it's saying "No flights found"? Are you sure you have data in your database? Most likely you need to do that or fix your query. Commented Jul 11, 2020 at 0:38
  • If you're fetching Flight.all the line before, just use a @flights.select afterwards. Commented Jul 12, 2020 at 8:27

1 Answer 1

1

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.