Skip to content

Commit

Permalink
feat: send booking conf email
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-garwood committed Nov 12, 2024
1 parent 507a208 commit e8922ba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/controllers/bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions app/mailers/passenger_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ul>
<br>
<p>
You can view your booking <%= link_to "here", show_booking_url(@booking) %>.
You can view your booking <%= link_to "here", @url %>.
</p>
<p>Thank you for booking with us. We look forward to seeing you on board.</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit e8922ba

Please sign in to comment.