Add & Display Flights

This commit is contained in:
2022-01-15 16:05:31 -05:00
parent 796a070af4
commit 022b63fc1a
26 changed files with 395 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*/
@import "bootstrap";

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the Flights controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -0,0 +1,29 @@
class FlightsController < ApplicationController
# Display past flights
def index
@flights = Flight.all
end
# Display single flight
def show
@flight = Flight.find(params[:id])
end
def new
@flight = Flight.new
@aircraft = Aircraft.all
@flight.date = Date.current
end
def create
@flight = Flight.new(params)
if @flight.save
redirect_to @flight
else
render :new, status: :unprocessable_entity
end
end
end

View File

@@ -0,0 +1,2 @@
module FlightsHelper
end

12
app/models/aircraft.rb Normal file
View File

@@ -0,0 +1,12 @@
class Aircraft < ApplicationRecord
has_one :inspection
has_many :engine
has_many :flights
validates :reg, presence: true
validates :serial, presence: true
def to_s
return reg
end
end

3
app/models/engine.rb Normal file
View File

@@ -0,0 +1,3 @@
class Engine < ApplicationRecord
belongs_to :aircraft
end

12
app/models/flight.rb Normal file
View File

@@ -0,0 +1,12 @@
class Flight < ApplicationRecord
belongs_to :aircraft
validates :to, presence: true
validates :from, presence: true
validates :tach, presence: true
validates :hobbs, presence: true
validates :date, presence: true
def title
return aircraft.reg << " - " << date.to_s << " - " << time.to_s
end
end

3
app/models/inspection.rb Normal file
View File

@@ -0,0 +1,3 @@
class Inspection < ApplicationRecord
belongs_to :aircraft
end

View File

@@ -0,0 +1,9 @@
<h1>Flights</h1>
<ul>
<% @flights.each do |flight| %>
<li>
<%= link_to flight.title, flight %>
</li>
<% end %>
</ul>

View File

@@ -0,0 +1,47 @@
<h1>New Flight</h1>
<%= form_with model: @flight do |form| %>
<div>
<%= form.label :aircraft %><br>
<%= form.select :aircraft, @aircraft %>
</div>
<div>
<%= form.label :date %><br>
<%= form.date_field :date %>
</div>
<div>
<%= form.label :from %><br>
<%= form.text_field :from %>
</div>
<div>
<%= form.label :to %><br>
<%= form.text_field :to %>
</div>
<div>
<%= form.label :tach %><br>
<%= form.number_field :tach %>
</div>
<div>
<%= form.label :hobbs %><br>
<%= form.number_field :hobbs %>
</div>
<div>
<%= form.label :fuel %><br>
<%= form.check_box :fuel %>
</div>
<div>
<%= form.label :oil %><br>
<%= form.check_box :oil %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,10 @@
<h1><%= @flight.date %></h1>
<h3><%= @flight.aircraft.reg %></h3>
<p> <b>From:</b> <%= @flight.from %></p>
<p> <b>To:</b> <%= @flight.to %></p>
<p> <b>Tach:</b> <%= @flight.tach %></p>
<p> <b>Hobbs:</b> <%= @flight.hobbs %></p>
<p> <b>Fuel Added:</b> <%= @flight.fuel %></p>
<p> <b>Oil Added:</b> <%= @flight.oil %></p>
<p> <b>Total Flight Time:</b> <%= @flight.time %></p>