Skip to content

The Odin Project practice app that allows a user to book their flight. See https://www.theodinproject.com/lessons/ruby-on-rails-flight-booker for more information.

Notifications You must be signed in to change notification settings

Rattlehead90/flight-booker

Repository files navigation

Gist

This app simulates the basic functions of a flight-booking app.

A typical airline booking flow:

  • Enter desired dates / airports and click “Search” 📅
  • Choose from among a list of available flights 🛫
  • Enter passenger information for all passengers 🧑
  • Enter billing information 💶

See more at (https://www.theodinproject.com/lessons/ruby-on-rails-flight-booker)

Demo

Main Goal

I've created this barebones app to practice backend for nested forms and complex associations (see database diagram below).

Details

database diagram

The airports were associated with flights as arrival and departure airports.

# app/models/airport.rb
has_many :departure_flights, class_name: 'Flight',
                            foreign_key: 'departure_airport_id', 
                              dependent: :destroy

has_many :arrival_flights, class_name: 'Flight',
                          foreign_key: 'arrival_airport_id',
                            dependent: :destroy
#app/models/flight.rb
belongs_to :departure_airport, class_name: 'Airport',
                              foreign_key: 'departure_airport_id'
belongs_to :arrival_airport, class_name: 'Airport',
                            foreign_key: 'arrival_airport_id'

The main core of the database though are the connections between Bookings, Flights and Passengers models. The idea was to allow each flight to onboard many passengers and each passenger to board many flights through booking model (so many-to-many through).

#app/models/flight.rb
has_many :bookings, foreign_key: :flight_id
has_many :passengers, through: :bookings, source: :passenger
#app/models/booking.rb
has_many :passengers
belongs_to :flight
#app/models/passenger.rb
belongs_to :booking
has_many :flights, through: :bookings

That was the backend at the proverbial fingertips of the controllers to throw the the whole book-the-flight-to-London-next-month proces.

About

The Odin Project practice app that allows a user to book their flight. See https://www.theodinproject.com/lessons/ruby-on-rails-flight-booker for more information.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published