diff --git a/app/controllers/bookings_controller.rb b/app/controllers/bookings_controller.rb index 1244e06..3f065be 100644 --- a/app/controllers/bookings_controller.rb +++ b/app/controllers/bookings_controller.rb @@ -15,6 +15,7 @@ def create @flight = Flight.find(booking_params[:flight_id]) @booking.number_of_tickets = @booking.passengers.compact.size if @booking.save + PassengerMailer.with(booking: @booking).booking_confirmation_email.deliver_later flash[:notice] = "Booking created!" redirect_to @booking else diff --git a/app/mailers/passenger_mailer.rb b/app/mailers/passenger_mailer.rb index c8c21eb..1c8b3c4 100644 --- a/app/mailers/passenger_mailer.rb +++ b/app/mailers/passenger_mailer.rb @@ -4,10 +4,14 @@ class PassengerMailer < ApplicationMailer # confirmation email to be sent after a booking is made def booking_confirmation_email - @passengers = @booking.passengers + @booking = params[:booking] @url = booking_url(@booking) + @passengers = @booking.passengers + @flight = @booking.flight + debugger @passengers.each do |passenger| - mail(to: passenger.email, subject: "Booking Confirmation | flight ##{@booking.flight.id}") + @passenger = passenger + mail(to: passenger.email, subject: "Booking Confirmation | flight ##{@flight.id}") end end end diff --git a/app/views/passenger_mailer/booking_confirmation_email.html.erb b/app/views/passenger_mailer/booking_confirmation_email.html.erb index bb3c00b..6ec4e46 100644 --- a/app/views/passenger_mailer/booking_confirmation_email.html.erb +++ b/app/views/passenger_mailer/booking_confirmation_email.html.erb @@ -9,7 +9,7 @@

- You can view your booking <%= link_to "here", show_booking_url(@booking) %>. + You can view your booking <%= link_to "here", @url %>.

Thank you for booking with us. We look forward to seeing you on board.

diff --git a/app/views/passenger_mailer/booking_confirmation_email.text.erb b/app/views/passenger_mailer/booking_confirmation_email.text.erb index f37ad94..9c40c4a 100644 --- a/app/views/passenger_mailer/booking_confirmation_email.text.erb +++ b/app/views/passenger_mailer/booking_confirmation_email.text.erb @@ -5,5 +5,5 @@ Flight number: <%= @flight.id %> Departure: <%= @flight.departure_airport.code %> Arrival: <%= @flight.arrival_airport.code %> Departure time: <%= @flight.departure_time %> -You can view your booking <%= link_to "here", show_booking_url(@booking) %>. +You can view your booking <%= link_to "here", @url %>. Thank you for booking with us. We look forward to seeing you on board.