Coder Social home page Coder Social logo

flight-booker's Introduction

Project: Flight Booker

What's this

A project completed as part of The Odin Ruby on Rails Learning Track to tackle some advanced forms. The project involves building of a typical checkout process for booking a one-way flight.

Functionality

A toy app designed to help the users find and book one-way flights on a specific date for up to four passengers. For the purposes of this project, it is not necessary signing up or logging in to use the app. This project is meant to solidify concepts in data associations (see Data Models block) and more 'advanced' form techniques, such as pre-populating data from multiple models through select helpers and usage of nested attributes. Nevertheless, the styling was not requested, I built a minimalistic design using bulma gem, a CSS framework based on Flexbox.

Live Demo

You can try it out here
HEADS UP: Heroku server may need up to 30 sec to fire up a dyno. Be patient! :)

Screenshots

Landing page aka #index

Flight booker home page

Search results

Flight booker search results

Passenger details

Flight booker passenger details

Booking Form

Flight booker booking form

Getting started

To get started with the app, make sure you have Rails and Git installed on your machine
Clone the repo to your local machine:

$ git clone https://github.com/Pandenok/flight-booker

Then, install the needed gems:

$ bundle install

Next, migrate the database:

$ rails db:migrate

Load sample airports and flights:

$ rails db:seed

Finally, on root path run a local server:

$ rails server

Open browser to view application:

localhost:3000

Built With

  • Ruby on Rails - Web framework
  • Bulma - CSS framework
  • Heroku - Cloud platform/server

Data Models

class Airport < ApplicationRecord
  has_many :departing_flights, class_name: "Flight", foreign_key: "from_airport_id" 
  has_many :arriving_flights,  class_name: "Flight", foreign_key: "to_airport_id"
end
class Flight < ApplicationRecord
  belongs_to :from_airport, class_name: "Airport", foreign_key: "from_airport_id"
  belongs_to :to_airport, class_name: "Airport", foreign_key: "to_airport_id"
  has_many :bookings
  has_many :passengers, through: :bookings
end
class Booking < ApplicationRecord
  belongs_to :flight
  has_many :passengers
  accepts_nested_attributes_for :passengers
end
class Passenger < ApplicationRecord
  belongs_to :booking
end

Reflection

  1. In the assignment it's suggested to

make your seeds file ::delete_all items from each table in your database and then completely repopulate them. That way, when you create a new model or change how you want your sample data set up, you can just update the seeds.rb file and rerun $ rake db:seed.

This trick does delete the entries from the tables, but it doesn't reset the counts for new ids. After doing some more research on this topic, I found some snippets here, here and here and I combined them into the following:

tables = ActiveRecord::Base.connection.tables - ['schema_migrations']

# In PostgreSQL, it does not do this automatically. You can use TRUNCATE TABLE table RESTART IDENTITY;
# To automatically truncate all tables that have foreign-key references to any of the named tables use CASCADE.
# tables.each do |table|
#   ActiveRecord::Base.connection.execute("TRUNCATE #{table} RESTART IDENTITY CASCADE")
# end

# In SQLite, there is no TRUNCATE statement, instead, it's
tables.each do |table|
  ActiveRecord::Base.connection.execute "DELETE FROM `#{table}`"
  ActiveRecord::Base.connection.execute "DELETE FROM sqlite_sequence WHERE name='#{table}'"
end
  1. I haven't found how to hide a prompt message from dropdown list. There is a similar question on SO, but no solution was provided. Here is a handy fiddle to visualize the wanted result.
  2. While fixing the bug on invalid date in params I found this answer, which helped me understand the difference between has_key?, key?, blank?, nil?, present?
  3. I don't know how to disable the submit button on search_results_form if there is no value selected or how to throw an error, so I've just set a parameter of radio button to { checked: true }. All the suggestions I found were involving JavaScript. I may come back to that one day and fix it.
  4. I feel rather confident with bulma, maybe it's time to try some new front-end frameworks, like materialize or bootstrap.
  5. I definitely need to learn simple form gem as well.
  6. Setting up a mailer was pretty much easy task. It’s very similar to building a new controller and views. In order to not fire off a bunch of emails when testing app in the development environment letter_opener gem was used and its configuration is rather straightforward.

flight-booker's People

Contributors

pandenok avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.