-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added bookings controller * Added booking model * Added booking migration * radio button for selecting a flight * button to submit data to create booking todo: figure out how to wire turbodrive so that the params persist after the form is submitted chore: add passenger ref to bookings * css stylesheet for flashes * show flashes in app layouts
- Loading branch information
1 parent
5fd06f8
commit e989c0d
Showing
15 changed files
with
131 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class BookingsController < ApplicationController | ||
def new | ||
@booking = Booking.new | ||
end | ||
|
||
def create | ||
@booking = Booking.new(booking_params) | ||
@booking.passenger = current_user | ||
|
||
if @booking.save | ||
redirect_to @booking | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def booking_params | ||
params.require(:booking).permit(:flight_id, :passenger_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module BookingsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Booking < ApplicationRecord | ||
belongs_to :passenger, class_name: "User", foreign_key: "passenger_id" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
<h2 class="flight-results"> | ||
Flight results | ||
</h2> | ||
<table> | ||
<td class="flights"> | ||
<tr> | ||
<th>Departs from</th> | ||
<th>Arrives at</th> | ||
<th>Depart time</th> | ||
<th>Duration</th> | ||
<th>Available seats</th> | ||
</tr> | ||
<% @flights.each do |flight| %> | ||
<%= form_with url: bookings_path, method: :post, local: true do |form| %> | ||
<table> | ||
<thead> | ||
<tr> | ||
<td> | ||
<%= flight.departure_airport.code %> | ||
</td> | ||
<td> | ||
<%= flight.arrival_airport.code %> | ||
</td> | ||
<td> | ||
<%= flight.depart_time %> | ||
</td> | ||
<td> | ||
<%# duration is in minutes, so we need to format as HH:MM %> | ||
<%= Time.at(flight.duration * 60).utc.strftime("%H:%M") %> | ||
</td> | ||
<td> | ||
<%= flight.available_seats %> | ||
</td> | ||
<th>Departs from</th> | ||
<th>Arrives at</th> | ||
<th>Depart time</th> | ||
<th>Duration</th> | ||
<th>Available seats</th> | ||
<th>Select</th> | ||
</tr> | ||
<% end %> | ||
</td> | ||
</table> | ||
</thead> | ||
<tbody> | ||
<% @flights.each do |flight| %> | ||
<tr> | ||
<td> | ||
<%= flight.departure_airport.code %> | ||
</td> | ||
<td> | ||
<%= flight.arrival_airport.code %> | ||
</td> | ||
<td> | ||
<%= flight.depart_time %> | ||
</td> | ||
<td> | ||
<%= Time.at(flight.duration * 60).utc.strftime("%H:%M") %> | ||
</td> | ||
<td> | ||
<%= flight.available_seats %> | ||
</td> | ||
<td> | ||
<%= form.radio_button :selected_flight_id, flight.id %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<%= form.submit "Book Selected Flight" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CreateBookings < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :bookings do |t| | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddPassengerRefToBookings < ActiveRecord::Migration[7.2] | ||
def change | ||
add_reference :bookings, :passenger, null: false, foreign_key: { to_table: :users } | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class BookingsControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
# model remove the "{}" from the fixture names and add the columns immediately | ||
# below each fixture, per the syntax in the comments below | ||
# | ||
one: {} | ||
# column: value | ||
# | ||
two: {} | ||
# column: value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class BookingTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |