From 0fa4ab2c7007f5f7175a13c6c8b1f269b7172e9a Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 15:22:00 -0700 Subject: [PATCH 01/56] We added rails --- .gitignore | 22 ++ Gemfile | 70 ++++++ Gemfile.lock | 225 ++++++++++++++++++ Rakefile | 6 + app/assets/config/manifest.js | 3 + app/assets/images/.keep | 0 app/assets/javascripts/application.js | 15 ++ app/assets/javascripts/cable.js | 13 + app/assets/javascripts/channels/.keep | 0 app/assets/stylesheets/application.css | 15 ++ app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + app/controllers/application_controller.rb | 3 + app/controllers/concerns/.keep | 0 app/helpers/application_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/views/layouts/application.html.erb | 14 ++ app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 38 +++ bin/spring | 17 ++ bin/update | 29 +++ bin/yarn | 11 + config.ru | 5 + config/application.rb | 25 ++ config/boot.rb | 3 + config/cable.yml | 10 + config/database.yml | 85 +++++++ config/environment.rb | 5 + config/environments/development.rb | 54 +++++ config/environments/production.rb | 91 +++++++ config/environments/test.rb | 42 ++++ .../application_controller_renderer.rb | 8 + config/initializers/assets.rb | 14 ++ config/initializers/backtrace_silencers.rb | 7 + config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 ++ config/initializers/mime_types.rb | 4 + config/initializers/wrap_parameters.rb | 14 ++ config/locales/en.yml | 33 +++ config/puma.rb | 56 +++++ config/routes.rb | 3 + config/secrets.yml | 32 +++ config/spring.rb | 6 + lib/assets/.keep | 0 lib/tasks/.keep | 0 log/.keep | 0 package.json | 5 + public/404.html | 67 ++++++ public/422.html | 67 ++++++ public/500.html | 66 +++++ public/apple-touch-icon-precomposed.png | 0 public/apple-touch-icon.png | 0 public/favicon.ico | 0 public/robots.txt | 1 + test/application_system_test_case.rb | 5 + test/controllers/.keep | 0 test/fixtures/.keep | 0 test/fixtures/files/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/system/.keep | 0 test/test_helper.rb | 26 ++ tmp/.keep | 0 vendor/.keep | 0 74 files changed, 1294 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/javascripts/cable.js create mode 100644 app/assets/javascripts/channels/.keep create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/helpers/application_helper.rb create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100755 bin/update create mode 100755 bin/yarn create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/secrets.yml create mode 100644 config/spring.rb create mode 100644 lib/assets/.keep create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 package.json create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/apple-touch-icon-precomposed.png create mode 100644 public/apple-touch-icon.png create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 test/application_system_test_case.rb create mode 100644 test/controllers/.keep create mode 100644 test/fixtures/.keep create mode 100644 test/fixtures/files/.keep create mode 100644 test/helpers/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/system/.keep create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 vendor/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e74c03379 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +/node_modules +/yarn-error.log + +.byebug_history +/coverage +.DS_Store + diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..9f37ac349 --- /dev/null +++ b/Gemfile @@ -0,0 +1,70 @@ +source 'https://rubygems.org' + +git_source(:github) do |repo_name| + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://github.com/#{repo_name}.git" +end + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.1.5' +# Use postgresql as the database for Active Record +gem 'pg', '>= 0.18', '< 2.0' +# Use Puma as the app server +gem 'puma', '~> 3.7' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +# gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '~> 2.13' + gem 'selenium-webdriver' +end + +group :development do + # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '>= 3.0.5', '< 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-turbolinks' +gem 'jquery-rails' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..51a4002af --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,225 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.1.5) + actionpack (= 5.1.5) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.5) + actionpack (= 5.1.5) + actionview (= 5.1.5) + activejob (= 5.1.5) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.1.5) + actionview (= 5.1.5) + activesupport (= 5.1.5) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.5) + activesupport (= 5.1.5) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.1.5) + activesupport (= 5.1.5) + globalid (>= 0.3.6) + activemodel (5.1.5) + activesupport (= 5.1.5) + activerecord (5.1.5) + activemodel (= 5.1.5) + activesupport (= 5.1.5) + arel (~> 8.0) + activesupport (5.1.5) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ansi (1.5.0) + arel (8.0.0) + better_errors (2.4.0) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) + bindex (0.5.0) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) + builder (3.2.3) + byebug (10.0.0) + capybara (2.18.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (>= 2.0, < 4.0) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + coderay (1.1.2) + concurrent-ruby (1.0.5) + crass (1.0.3) + debug_inspector (0.0.3) + erubi (1.7.1) + execjs (2.7.0) + ffi (1.9.23) + globalid (0.4.1) + activesupport (>= 4.2.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-turbolinks (2.1.0) + railties (>= 3.1.0) + turbolinks + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.2.2) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.1.19) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + multi_json (1.13.1) + nio4r (2.3.0) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + pg (1.0.0) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.6) + pry (>= 0.10.4) + public_suffix (3.0.2) + puma (3.11.3) + rack (2.0.4) + rack-test (1.0.0) + rack (>= 1.0, < 3) + rails (5.1.5) + actioncable (= 5.1.5) + actionmailer (= 5.1.5) + actionpack (= 5.1.5) + actionview (= 5.1.5) + activejob (= 5.1.5) + activemodel (= 5.1.5) + activerecord (= 5.1.5) + activesupport (= 5.1.5) + bundler (>= 1.3.0) + railties (= 5.1.5) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.1.5) + actionpack (= 5.1.5) + activesupport (= 5.1.5) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + ruby-progressbar (1.9.0) + ruby_dep (1.5.0) + rubyzip (1.2.1) + sass (3.5.5) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (3.11.0) + childprocess (~> 0.5) + rubyzip (~> 1.2) + spring (2.0.2) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + turbolinks (5.1.0) + turbolinks-source (~> 5.1) + turbolinks-source (5.1.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.8) + execjs (>= 0.3.0, < 3) + web-console (3.5.1) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.0.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + byebug + capybara (~> 2.13) + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.7) + rails (~> 5.1.5) + sass-rails (~> 5.0) + selenium-webdriver + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +BUNDLED WITH + 1.16.1 diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..e85f91391 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 000000000..b16e53d6d --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 000000000..46b20359f --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,15 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's +// vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require rails-ujs +//= require turbolinks +//= require_tree . diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 000000000..739aa5f02 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 000000000..d05ea0f51 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -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. + * + *= require_tree . + *= require_self + */ diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 000000000..d67269728 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 000000000..0ff5442f4 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 000000000..1c07694e9 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery with: :exception +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 000000000..a009ace51 --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 000000000..286b2239d --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 000000000..353326840 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + RideshareRails + <%= csrf_meta_tags %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 000000000..cbd34d2e9 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 000000000..37f0bddbd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 000000000..5badb2fde --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 000000000..d87d5f578 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..78c4e861d --- /dev/null +++ b/bin/setup @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 000000000..fb2ec2ebb --- /dev/null +++ b/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == "spring" } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/bin/update b/bin/update new file mode 100755 index 000000000..a8e4462f2 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 000000000..c2bacef83 --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +VENDOR_PATH = File.expand_path('..', __dir__) +Dir.chdir(VENDOR_PATH) do + begin + exec "yarnpkg #{ARGV.join(" ")}" + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 000000000..f7ba0b527 --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 000000000..4c6d223cf --- /dev/null +++ b/config/application.rb @@ -0,0 +1,25 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module RideshareRails + class Application < Rails::Application + config.generators do |g| + # Force new test files to be generated in the minitest-spec style + g.test_framework :minitest, spec: true + + # Always use .js files, never .coffee + g.javascript_engine :js + end + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.1 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 000000000..30f5120df --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 000000000..db55d1026 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 + channel_prefix: rideshare-rails_production diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 000000000..bf1c2b58e --- /dev/null +++ b/config/database.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 9.1 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see Rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +development: + <<: *default + database: rideshare-rails_development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: rideshare-rails + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: rideshare-rails_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: rideshare-rails_production + username: rideshare-rails + password: <%= ENV['RIDESHARE-RAILS_DATABASE_PASSWORD'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 000000000..426333bb4 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 000000000..5187e2218 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,54 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 000000000..8eb974095 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,91 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Attempt to read encrypted secrets from `config/secrets.yml.enc`. + # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or + # `config/secrets.yml.key`. + config.read_encrypted_secrets = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "rideshare-rails_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 000000000..8e5cbde53 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..89d2efab2 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..4b828e80c --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 000000000..59385cdf3 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..5a6a32d37 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 000000000..ac033bf9d --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 000000000..dc1899682 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..bbfc3961b --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 000000000..decc5a857 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 000000000..1e19380dc --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,56 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# If you are preloading your application and using Active Record, it's +# recommended that you close any connections to the database before workers +# are forked to prevent connection leakage. +# +# before_fork do +# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) +# end + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted, this block will be run. If you are using the `preload_app!` +# option, you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, as Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end +# + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 000000000..787824f88 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 000000000..1f1d6a611 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,32 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rails secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +# Shared secrets are available across all environments. + +# shared: +# api_key: a1B2c3D4e5F6 + +# Environmental secrets are only available for that specific environment. + +development: + secret_key_base: b8c97a382a7c393f42cc1a0d85698044251f13421abecb996b506f232b8ed920a04cfe14f578b78e8bed7c1d4d2b4af14c9cbeab34fef00263e330a0289565cb + +test: + secret_key_base: b3dcb59cc078843fd61f6c0948b151431680115d3ccc13a4fd37014297e08dec0de7d49a21036d57f83963c66ed36fcabf655fd37dae2706f2b2acf107c205ec + +# Do not keep production secrets in the unencrypted secrets file. +# Instead, either read values from the environment. +# Or, use `bin/rails secrets:setup` to configure encrypted secrets +# and move the `production:` environment over there. + +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 000000000..c9119b40c --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) } diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/log/.keep b/log/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json new file mode 100644 index 000000000..2d821c4e4 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "rideshare-rails", + "private": true, + "dependencies": {} +} diff --git a/public/404.html b/public/404.html new file mode 100644 index 000000000..2be3af26f --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/422.html b/public/422.html new file mode 100644 index 000000000..c08eac0d1 --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/500.html b/public/500.html new file mode 100644 index 000000000..78a030af2 --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png new file mode 100644 index 000000000..e69de29bb diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 000000000..e69de29bb diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 000000000..37b576a4a --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 000000000..d19212abd --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 000000000..10594a324 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,26 @@ +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails" +require "minitest/reporters" # for Colorized output + +# For colorful output! +Minitest::Reporters.use!( + Minitest::Reporters::SpecReporter.new, + ENV, + Minitest.backtrace_filter +) + + +# To add Capybara feature tests add `gem "minitest-rails-capybara"` +# to the test group in the Gemfile and uncomment the following: +# require "minitest/rails/capybara" + +# Uncomment for awesome colorful output +# require "minitest/pride" + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + # Add more helper methods to be used by all tests here... +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 000000000..e69de29bb From 142c169b7d82fba2bfeb0e4bea60d5b9f014f571 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Mon, 2 Apr 2018 16:33:34 -0700 Subject: [PATCH 02/56] created Driver and Passenger models --- app/models/driver.rb | 2 ++ app/models/passenger.rb | 2 ++ .../20180402232913_create_passengers.rb | 10 ++++++ db/migrate/20180402233200_create_drivers.rb | 10 ++++++ db/schema.rb | 32 +++++++++++++++++++ test/fixtures/drivers.yml | 11 +++++++ test/fixtures/passengers.yml | 11 +++++++ test/models/driver_test.rb | 9 ++++++ test/models/passenger_test.rb | 9 ++++++ 9 files changed, 96 insertions(+) create mode 100644 app/models/driver.rb create mode 100644 app/models/passenger.rb create mode 100644 db/migrate/20180402232913_create_passengers.rb create mode 100644 db/migrate/20180402233200_create_drivers.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/drivers.yml create mode 100644 test/fixtures/passengers.yml create mode 100644 test/models/driver_test.rb create mode 100644 test/models/passenger_test.rb diff --git a/app/models/driver.rb b/app/models/driver.rb new file mode 100644 index 000000000..1ff364562 --- /dev/null +++ b/app/models/driver.rb @@ -0,0 +1,2 @@ +class Driver < ApplicationRecord +end diff --git a/app/models/passenger.rb b/app/models/passenger.rb new file mode 100644 index 000000000..2c5748ac2 --- /dev/null +++ b/app/models/passenger.rb @@ -0,0 +1,2 @@ +class Passenger < ApplicationRecord +end diff --git a/db/migrate/20180402232913_create_passengers.rb b/db/migrate/20180402232913_create_passengers.rb new file mode 100644 index 000000000..97f19c7b4 --- /dev/null +++ b/db/migrate/20180402232913_create_passengers.rb @@ -0,0 +1,10 @@ +class CreatePassengers < ActiveRecord::Migration[5.1] + def change + create_table :passengers do |t| + t.string :name + t.string :phone_num + + t.timestamps + end + end +end diff --git a/db/migrate/20180402233200_create_drivers.rb b/db/migrate/20180402233200_create_drivers.rb new file mode 100644 index 000000000..8800d7db3 --- /dev/null +++ b/db/migrate/20180402233200_create_drivers.rb @@ -0,0 +1,10 @@ +class CreateDrivers < ActiveRecord::Migration[5.1] + def change + create_table :drivers do |t| + t.string :name + t.string :vin + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..52537d632 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,32 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20180402233200) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "drivers", force: :cascade do |t| + t.string "name" + t.string "vin" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "passengers", force: :cascade do |t| + t.string "name" + t.string "phone_num" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/fixtures/drivers.yml b/test/fixtures/drivers.yml new file mode 100644 index 000000000..dc3ee79b5 --- /dev/null +++ b/test/fixtures/drivers.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://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 diff --git a/test/fixtures/passengers.yml b/test/fixtures/passengers.yml new file mode 100644 index 000000000..dc3ee79b5 --- /dev/null +++ b/test/fixtures/passengers.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://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 diff --git a/test/models/driver_test.rb b/test/models/driver_test.rb new file mode 100644 index 000000000..203cc4e33 --- /dev/null +++ b/test/models/driver_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Driver do + let(:driver) { Driver.new } + + it "must be valid" do + value(driver).must_be :valid? + end +end diff --git a/test/models/passenger_test.rb b/test/models/passenger_test.rb new file mode 100644 index 000000000..3f55ffd00 --- /dev/null +++ b/test/models/passenger_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Passenger do + let(:passenger) { Passenger.new } + + it "must be valid" do + value(passenger).must_be :valid? + end +end From dd7d2b7528322fef1fdcee9774cc9c983fd128cc Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 16:46:39 -0700 Subject: [PATCH 03/56] ralated trip and driver --- app/models/trip.rb | 2 ++ db/migrate/20180402233450_create_trips.rb | 11 +++++++++++ db/migrate/20180402234306_add_trips_to_driver.rb | 5 +++++ db/schema.rb | 13 ++++++++++++- test/fixtures/trips.yml | 11 +++++++++++ test/models/trip_test.rb | 9 +++++++++ 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 app/models/trip.rb create mode 100644 db/migrate/20180402233450_create_trips.rb create mode 100644 db/migrate/20180402234306_add_trips_to_driver.rb create mode 100644 test/fixtures/trips.yml create mode 100644 test/models/trip_test.rb diff --git a/app/models/trip.rb b/app/models/trip.rb new file mode 100644 index 000000000..a8c077a10 --- /dev/null +++ b/app/models/trip.rb @@ -0,0 +1,2 @@ +class Trip < ApplicationRecord +end diff --git a/db/migrate/20180402233450_create_trips.rb b/db/migrate/20180402233450_create_trips.rb new file mode 100644 index 000000000..3b7b7e1e2 --- /dev/null +++ b/db/migrate/20180402233450_create_trips.rb @@ -0,0 +1,11 @@ +class CreateTrips < ActiveRecord::Migration[5.1] + def change + create_table :trips do |t| + t.date :date + t.integer :rating + t.float :cost + + t.timestamps + end + end +end diff --git a/db/migrate/20180402234306_add_trips_to_driver.rb b/db/migrate/20180402234306_add_trips_to_driver.rb new file mode 100644 index 000000000..eebd13bf0 --- /dev/null +++ b/db/migrate/20180402234306_add_trips_to_driver.rb @@ -0,0 +1,5 @@ +class AddTripsToDriver < ActiveRecord::Migration[5.1] + def change + add_reference :trips, :driver, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 52537d632..1ea42d4c4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180402233200) do +ActiveRecord::Schema.define(version: 20180402234306) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -29,4 +29,15 @@ t.datetime "updated_at", null: false end + create_table "trips", force: :cascade do |t| + t.date "date" + t.integer "rating" + t.float "cost" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "driver_id" + t.index ["driver_id"], name: "index_trips_on_driver_id" + end + + add_foreign_key "trips", "drivers" end diff --git a/test/fixtures/trips.yml b/test/fixtures/trips.yml new file mode 100644 index 000000000..dc3ee79b5 --- /dev/null +++ b/test/fixtures/trips.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://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 diff --git a/test/models/trip_test.rb b/test/models/trip_test.rb new file mode 100644 index 000000000..6bbc51182 --- /dev/null +++ b/test/models/trip_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Trip do + let(:trip) { Trip.new } + + it "must be valid" do + value(trip).must_be :valid? + end +end From 4097ca92c4eebef773239ce7a951febdba8881cc Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Mon, 2 Apr 2018 16:50:08 -0700 Subject: [PATCH 04/56] related passenger and trip models, added relationships in model --- app/models/driver.rb | 1 + app/models/passenger.rb | 1 + app/models/trip.rb | 1 + db/migrate/20180402234723_add_trips_to_passenger.rb | 5 +++++ db/schema.rb | 5 ++++- 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180402234723_add_trips_to_passenger.rb diff --git a/app/models/driver.rb b/app/models/driver.rb index 1ff364562..197e65507 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -1,2 +1,3 @@ class Driver < ApplicationRecord + has_many :trips end diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 2c5748ac2..2fef89192 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,2 +1,3 @@ class Passenger < ApplicationRecord + has_many :trips end diff --git a/app/models/trip.rb b/app/models/trip.rb index a8c077a10..28c02c3a8 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,2 +1,3 @@ class Trip < ApplicationRecord + belongs_to :driver, :passenger end diff --git a/db/migrate/20180402234723_add_trips_to_passenger.rb b/db/migrate/20180402234723_add_trips_to_passenger.rb new file mode 100644 index 000000000..b4e9bdf2f --- /dev/null +++ b/db/migrate/20180402234723_add_trips_to_passenger.rb @@ -0,0 +1,5 @@ +class AddTripsToPassenger < ActiveRecord::Migration[5.1] + def change + add_reference :trips, :passenger, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 1ea42d4c4..85b89887e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180402234306) do +ActiveRecord::Schema.define(version: 20180402234723) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -36,8 +36,11 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "driver_id" + t.bigint "passenger_id" t.index ["driver_id"], name: "index_trips_on_driver_id" + t.index ["passenger_id"], name: "index_trips_on_passenger_id" end add_foreign_key "trips", "drivers" + add_foreign_key "trips", "passengers" end From 43fc5786d8dcfadddb151a3d3c14ca7bc32c75bc Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 16:53:46 -0700 Subject: [PATCH 05/56] Created a controller for each model --- app/assets/javascripts/drivers.js | 2 ++ app/assets/javascripts/passengers.js | 2 ++ app/assets/javascripts/trips.js | 2 ++ app/assets/stylesheets/drivers.scss | 3 +++ app/assets/stylesheets/passengers.scss | 3 +++ app/assets/stylesheets/trips.scss | 3 +++ app/controllers/drivers_controller.rb | 2 ++ app/controllers/passengers_controller.rb | 2 ++ app/controllers/trips_controller.rb | 2 ++ app/helpers/drivers_helper.rb | 2 ++ app/helpers/passengers_helper.rb | 2 ++ app/helpers/trips_helper.rb | 2 ++ test/controllers/drivers_controller_test.rb | 7 +++++++ test/controllers/passengers_controller_test.rb | 7 +++++++ test/controllers/trips_controller_test.rb | 7 +++++++ 15 files changed, 48 insertions(+) create mode 100644 app/assets/javascripts/drivers.js create mode 100644 app/assets/javascripts/passengers.js create mode 100644 app/assets/javascripts/trips.js create mode 100644 app/assets/stylesheets/drivers.scss create mode 100644 app/assets/stylesheets/passengers.scss create mode 100644 app/assets/stylesheets/trips.scss create mode 100644 app/controllers/drivers_controller.rb create mode 100644 app/controllers/passengers_controller.rb create mode 100644 app/controllers/trips_controller.rb create mode 100644 app/helpers/drivers_helper.rb create mode 100644 app/helpers/passengers_helper.rb create mode 100644 app/helpers/trips_helper.rb create mode 100644 test/controllers/drivers_controller_test.rb create mode 100644 test/controllers/passengers_controller_test.rb create mode 100644 test/controllers/trips_controller_test.rb diff --git a/app/assets/javascripts/drivers.js b/app/assets/javascripts/drivers.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/drivers.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/passengers.js b/app/assets/javascripts/passengers.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/passengers.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/trips.js b/app/assets/javascripts/trips.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/trips.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/drivers.scss b/app/assets/stylesheets/drivers.scss new file mode 100644 index 000000000..186a23a88 --- /dev/null +++ b/app/assets/stylesheets/drivers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the drivers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/passengers.scss b/app/assets/stylesheets/passengers.scss new file mode 100644 index 000000000..abb89851f --- /dev/null +++ b/app/assets/stylesheets/passengers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the passengers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/trips.scss b/app/assets/stylesheets/trips.scss new file mode 100644 index 000000000..473cbc303 --- /dev/null +++ b/app/assets/stylesheets/trips.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the trips controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb new file mode 100644 index 000000000..951cb9876 --- /dev/null +++ b/app/controllers/drivers_controller.rb @@ -0,0 +1,2 @@ +class DriversController < ApplicationController +end diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb new file mode 100644 index 000000000..7b08e4832 --- /dev/null +++ b/app/controllers/passengers_controller.rb @@ -0,0 +1,2 @@ +class PassengersController < ApplicationController +end diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb new file mode 100644 index 000000000..4275f53c7 --- /dev/null +++ b/app/controllers/trips_controller.rb @@ -0,0 +1,2 @@ +class TripsController < ApplicationController +end diff --git a/app/helpers/drivers_helper.rb b/app/helpers/drivers_helper.rb new file mode 100644 index 000000000..e5fc532e4 --- /dev/null +++ b/app/helpers/drivers_helper.rb @@ -0,0 +1,2 @@ +module DriversHelper +end diff --git a/app/helpers/passengers_helper.rb b/app/helpers/passengers_helper.rb new file mode 100644 index 000000000..1af9e68f1 --- /dev/null +++ b/app/helpers/passengers_helper.rb @@ -0,0 +1,2 @@ +module PassengersHelper +end diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb new file mode 100644 index 000000000..04f333d46 --- /dev/null +++ b/app/helpers/trips_helper.rb @@ -0,0 +1,2 @@ +module TripsHelper +end diff --git a/test/controllers/drivers_controller_test.rb b/test/controllers/drivers_controller_test.rb new file mode 100644 index 000000000..3ba908d00 --- /dev/null +++ b/test/controllers/drivers_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe DriversController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/passengers_controller_test.rb b/test/controllers/passengers_controller_test.rb new file mode 100644 index 000000000..d57028e30 --- /dev/null +++ b/test/controllers/passengers_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe PassengersController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/trips_controller_test.rb b/test/controllers/trips_controller_test.rb new file mode 100644 index 000000000..8d4fa930b --- /dev/null +++ b/test/controllers/trips_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe TripsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end From 0f763c16f03c85e0513502d6f7f32ec1e016646c Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 16:57:45 -0700 Subject: [PATCH 06/56] added all routes --- config/routes.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 787824f88..0bb9ec03a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,10 @@ Rails.application.routes.draw do + + +resources :drivers +resources :trips +resources :passengers + + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From a74cdfcbf344d80ee25ab4054c4b6bfaf056b3d0 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Mon, 2 Apr 2018 17:10:44 -0700 Subject: [PATCH 07/56] fixed belongs_to in trip --- app/models/trip.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/trip.rb b/app/models/trip.rb index 28c02c3a8..8e2566cd8 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,3 +1,4 @@ class Trip < ApplicationRecord - belongs_to :driver, :passenger + belongs_to :driver + belongs_to :passenger end From 0570ed64f28bd77206c9e8d6a99ac6fc22ec587a Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Mon, 2 Apr 2018 17:33:18 -0700 Subject: [PATCH 08/56] added passengers_controller methods --- app/controllers/passengers_controller.rb | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 7b08e4832..ff9a250d4 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -1,2 +1,52 @@ class PassengersController < ApplicationController + + def index + @passengers = Passenger.all + end + + def new + @passenger = Passenger.new + end + + def create + @passenger = Passenger.find(params[:id]) + @passenger.new(passenger_params) + + if @passenger.save + redirect_to passengers_path + else + render :edit + end + end + + def show + passenger_id = params[:id] + @passenger = Passenger.find(passenger_id) + end + + def edit + @passenger = Passenger.find(params[:id]) + end + + def update + @passenger = Passenger.find(params[:id]) + @passenger.assign_attributes(passenger_params) + + if @passenger.save + redirect_to passengers_path + else + render :edit + end + end + + def delete + Passenger.destroy(params[:id]) + end + + private + + def passenger_params + return params.require(:passenger).permit(:name, :phone_num) + end + end From ea6a83b2a20e3517ed96fd3b162dcc873f4893d7 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Mon, 2 Apr 2018 17:43:12 -0700 Subject: [PATCH 09/56] added index view for passengers --- app/views/passengers/index.html.erb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/views/passengers/index.html.erb diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb new file mode 100644 index 000000000..ccdcf8bd8 --- /dev/null +++ b/app/views/passengers/index.html.erb @@ -0,0 +1,7 @@ +

All Passengers

+ +<%# the first 50 part is temporary %> +<% @passengers.first(50).each do |passenger| %> +

Passenger ID: <%= passenger.id %>

+

Passenger Name: <%= passenger.name %>

+<% end %> From 02cac59cdb57501da164903261a6fdc269ed1ab0 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 21:24:41 -0700 Subject: [PATCH 10/56] Added the methods for the driver controller and a template for drivers index --- app/controllers/drivers_controller.rb | 43 +++++++++++++++++++++++++++ app/views/drivers/index.html.erb | 7 +++++ 2 files changed, 50 insertions(+) create mode 100644 app/views/drivers/index.html.erb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 951cb9876..70e875129 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -1,2 +1,45 @@ class DriversController < ApplicationController + + def index + @drivers = Driver.all + end + + def new + @driver = Driver.new + end + + def show + @driver = Driver.find(params[:id]) + end + + def create + new_driver = Driver.new(driver_params) + if new_driver.save + redirect_to drivers_path + end + end + + def edit + @driver = Driver.find(params[:id]) + + end + + def update + updated_driver = Driver.find(params[:id]) + updated_driver = update_attributes(driver_params) + + if updated_driver.save + redirect_to drivers_path + + end + end + + + + + + private + def driver_params + return params.require(:driver).permit(:name, :vin) + end end diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb new file mode 100644 index 000000000..8a21d6aa3 --- /dev/null +++ b/app/views/drivers/index.html.erb @@ -0,0 +1,7 @@ +

Drivers

+ +<% @drivers.each do |driver| %> +

Id : <%=driver.id%>

+

Name : <%=driver.name%>

+

Vin : <%=driver.vin%>

+<%end%> From 0b4d90bc22dd6904f9f23cc2349b35839b655166 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 21:35:04 -0700 Subject: [PATCH 11/56] Added a template (view) for the driver show action --- app/views/drivers/edit.html.erb | 0 app/views/drivers/new.html.erb | 0 app/views/drivers/show.html.erb | 5 +++++ 3 files changed, 5 insertions(+) create mode 100644 app/views/drivers/edit.html.erb create mode 100644 app/views/drivers/new.html.erb create mode 100644 app/views/drivers/show.html.erb diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb new file mode 100644 index 000000000..f4b4ba41e --- /dev/null +++ b/app/views/drivers/show.html.erb @@ -0,0 +1,5 @@ +

Drivers info

+ +

<%=@driver.name%>

+

ID : <%=@driver.id%>

+

VIN : <%=@driver.vin%>

From d9a2304391c167bba43673e6f94a620b81644536 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 21:42:32 -0700 Subject: [PATCH 12/56] Added a form for editing and creating a new driver, and then using it in the edit.html.erb and new.html.erb views. We are able to update and add drivers --- app/views/drivers/_form.html.erb | 11 +++++++++++ app/views/drivers/edit.html.erb | 1 + app/views/drivers/new.html.erb | 1 + app/views/drivers/show.html.erb | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 app/views/drivers/_form.html.erb diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb new file mode 100644 index 000000000..2329e6582 --- /dev/null +++ b/app/views/drivers/_form.html.erb @@ -0,0 +1,11 @@ +

+ <%= page_title %> +

+<%= form_for @driver do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> + +<%= f.label :vin %> +<%= f.text_field :vin %> +<%= f.submit %> +<% end %> diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb index e69de29bb..e733f230f 100644 --- a/app/views/drivers/edit.html.erb +++ b/app/views/drivers/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" , locals: {page_title: "Update Driver"}%> diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index e69de29bb..fe2811b8f 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" , locals: {page_title: "Create New Driver"}%> diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index f4b4ba41e..ec9c9ac30 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,4 +1,4 @@ -

Drivers info

+

Drivers info:

<%=@driver.name%>

ID : <%=@driver.id%>

From 0e49ca358da20d8511ee187d55352872bf614641 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Mon, 2 Apr 2018 21:49:01 -0700 Subject: [PATCH 13/56] Fixed a bug in controller --- app/controllers/drivers_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 70e875129..78842f47b 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -25,10 +25,11 @@ def edit end def update - updated_driver = Driver.find(params[:id]) - updated_driver = update_attributes(driver_params) + + the_driver = Driver.find(params[:id]) + the_driver.update_attributes(driver_params) - if updated_driver.save + if the_driver.save redirect_to drivers_path end From cbc55ed445fec8bacbbf292fce34bb90f991a0fb Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Tue, 3 Apr 2018 11:56:15 -0700 Subject: [PATCH 14/56] made a main website page, linked it to drivers#index and passengers#index --- app/assets/javascripts/rideshare.js | 2 ++ app/assets/stylesheets/rideshare.scss | 3 +++ app/controllers/rideshare_controller.rb | 5 +++++ app/helpers/rideshare_helper.rb | 2 ++ app/views/rideshare/index.html.erb | 6 ++++++ config/routes.rb | 6 +++--- test/controllers/rideshare_controller_test.rb | 7 +++++++ 7 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/rideshare.js create mode 100644 app/assets/stylesheets/rideshare.scss create mode 100644 app/controllers/rideshare_controller.rb create mode 100644 app/helpers/rideshare_helper.rb create mode 100644 app/views/rideshare/index.html.erb create mode 100644 test/controllers/rideshare_controller_test.rb diff --git a/app/assets/javascripts/rideshare.js b/app/assets/javascripts/rideshare.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/rideshare.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/rideshare.scss b/app/assets/stylesheets/rideshare.scss new file mode 100644 index 000000000..45378ce3e --- /dev/null +++ b/app/assets/stylesheets/rideshare.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the rideshare controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/rideshare_controller.rb b/app/controllers/rideshare_controller.rb new file mode 100644 index 000000000..6846f840e --- /dev/null +++ b/app/controllers/rideshare_controller.rb @@ -0,0 +1,5 @@ +class RideshareController < ApplicationController + def index + end + +end diff --git a/app/helpers/rideshare_helper.rb b/app/helpers/rideshare_helper.rb new file mode 100644 index 000000000..7314f6fd4 --- /dev/null +++ b/app/helpers/rideshare_helper.rb @@ -0,0 +1,2 @@ +module RideshareHelper +end diff --git a/app/views/rideshare/index.html.erb b/app/views/rideshare/index.html.erb new file mode 100644 index 000000000..3d536a409 --- /dev/null +++ b/app/views/rideshare/index.html.erb @@ -0,0 +1,6 @@ +

Welcome to our Rideshare App

+ +<%= link_to 'For Drivers', drivers_path %> +

+ +<%= link_to 'For Passengers', passengers_path %> diff --git a/config/routes.rb b/config/routes.rb index 0bb9ec03a..445e84329 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,10 @@ Rails.application.routes.draw do - + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +root 'rideshare#index' resources :drivers resources :trips resources :passengers - - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +resources :rideshare, only: [:index] end diff --git a/test/controllers/rideshare_controller_test.rb b/test/controllers/rideshare_controller_test.rb new file mode 100644 index 000000000..58ed52764 --- /dev/null +++ b/test/controllers/rideshare_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe RideshareController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end From 36722a3bad9c331a322ccb7cfd0cefe0318d7599 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Tue, 3 Apr 2018 12:12:09 -0700 Subject: [PATCH 15/56] added views for passenger, updated action name for drivers partial --- app/views/drivers/_form.html.erb | 2 +- app/views/drivers/edit.html.erb | 2 +- app/views/drivers/new.html.erb | 2 +- app/views/drivers/show.html.erb | 2 +- app/views/passengers/_form.html.erb | 12 ++++++++++++ app/views/passengers/edit.html.erb | 1 + app/views/passengers/new.html.erb | 1 + app/views/passengers/show.html.erb | 5 +++++ 8 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/views/passengers/_form.html.erb create mode 100644 app/views/passengers/edit.html.erb create mode 100644 app/views/passengers/new.html.erb create mode 100644 app/views/passengers/show.html.erb diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb index 2329e6582..e9171da4c 100644 --- a/app/views/drivers/_form.html.erb +++ b/app/views/drivers/_form.html.erb @@ -7,5 +7,5 @@ <%= f.label :vin %> <%= f.text_field :vin %> -<%= f.submit %> +<%= f.submit action_name %> <% end %> diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb index e733f230f..5d4f1ecab 100644 --- a/app/views/drivers/edit.html.erb +++ b/app/views/drivers/edit.html.erb @@ -1 +1 @@ -<%= render partial: "form" , locals: {page_title: "Update Driver"}%> +<%= render partial: "form" , locals: {action_name: 'Edit Driver', page_title: "Update Driver"}%> diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index fe2811b8f..48ec3995f 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -1 +1 @@ -<%= render partial: "form" , locals: {page_title: "Create New Driver"}%> +<%= render partial: "form" , locals: {action_name: 'Add Driver', page_title: "Create New Driver"}%> diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index ec9c9ac30..3a4f44217 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,4 +1,4 @@ -

Drivers info:

+

Driver info:

<%=@driver.name%>

ID : <%=@driver.id%>

diff --git a/app/views/passengers/_form.html.erb b/app/views/passengers/_form.html.erb new file mode 100644 index 000000000..506430064 --- /dev/null +++ b/app/views/passengers/_form.html.erb @@ -0,0 +1,12 @@ +

+ <%= page_title %> +

+ +<%= form_for @passenger do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> + +<%= f.label :phone_num %> +<%= f.text_field :phone_num %> +<%= f.submit action_name %> +<% end %> diff --git a/app/views/passengers/edit.html.erb b/app/views/passengers/edit.html.erb new file mode 100644 index 000000000..3ef630e59 --- /dev/null +++ b/app/views/passengers/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" , locals: {action_name: 'Edit Passenger', page_title: "Create New Passenger"} %> diff --git a/app/views/passengers/new.html.erb b/app/views/passengers/new.html.erb new file mode 100644 index 000000000..1b271162e --- /dev/null +++ b/app/views/passengers/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" , locals: {action_name: 'Create Passenger', page_title: "Create New Passenger"} %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb new file mode 100644 index 000000000..70b7f4de6 --- /dev/null +++ b/app/views/passengers/show.html.erb @@ -0,0 +1,5 @@ +

Passenger info:

+ +

<%= @passenger.name %>

+

ID : <%= @passenger.id %>

+

Phone #: <%= @passenger.phone_num %>

From c482819444ab740f640a47da40016ab21f644775 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Tue, 3 Apr 2018 15:45:51 -0700 Subject: [PATCH 16/56] fixed form to find a drivers show page by name --- app/controllers/drivers_controller.rb | 11 ++++++++--- app/views/drivers/index.html.erb | 10 +++++++--- app/views/layouts/application.html.erb | 13 ++++++++++++- app/views/passengers/index.html.erb | 5 ++--- config/routes.rb | 2 ++ 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 78842f47b..2ee66cb61 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -15,7 +15,7 @@ def show def create new_driver = Driver.new(driver_params) if new_driver.save - redirect_to drivers_path + redirect_to driver_path(new_driver.id) end end @@ -25,7 +25,7 @@ def edit end def update - + the_driver = Driver.find(params[:id]) the_driver.update_attributes(driver_params) @@ -35,9 +35,14 @@ def update end end + # don't forget delete + def by_name + driver_name = params[:name] + @driver = Driver.find_by(name: driver_name) - + redirect_to driver_path(@driver.id) + end private def driver_params diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 8a21d6aa3..f2d7a5600 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,7 +1,11 @@

Drivers

+<%= form_tag by_name_path, method: :get do %> + <%= label_tag :name %> + <%= text_field_tag :name %> + <%= submit_tag %> +<% end %> + <% @drivers.each do |driver| %> -

Id : <%=driver.id%>

-

Name : <%=driver.name%>

-

Vin : <%=driver.vin%>

+

<%= link_to "#{driver.name}", driver_path(driver.id) %>

<%end%> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 353326840..9cfe6e808 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,6 +9,17 @@ - <%= yield %> +
+ +
+
+ <%= yield %> +
+
+
diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index ccdcf8bd8..5ec606402 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,7 +1,6 @@

All Passengers

<%# the first 50 part is temporary %> -<% @passengers.first(50).each do |passenger| %> -

Passenger ID: <%= passenger.id %>

-

Passenger Name: <%= passenger.name %>

+<% @passengers.each do |passenger| %> +

<%= link_to passenger.name, passenger_path(passenger) %>

<% end %> diff --git a/config/routes.rb b/config/routes.rb index 445e84329..10e34381f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,9 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'rideshare#index' +get 'drivers/by_name', to: 'drivers#by_name', as: 'by_name' resources :drivers + resources :trips resources :passengers From 5fb4e363b44a06cf081c36f893cf6443be4b3762 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Tue, 3 Apr 2018 16:14:23 -0700 Subject: [PATCH 17/56] Added partial form for searching by name both driver and passenger --- app/controllers/passengers_controller.rb | 7 +++++ app/controllers/trips_controller.rb | 34 ++++++++++++++++++++++++ app/views/drivers/index.html.erb | 7 +---- app/views/passengers/index.html.erb | 4 ++- app/views/shared/_find_by_name.html.erb | 6 +++++ config/routes.rb | 3 +++ 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 app/views/shared/_find_by_name.html.erb diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index ff9a250d4..62f191819 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -43,6 +43,13 @@ def delete Passenger.destroy(params[:id]) end + def by_name + passenger_name = params[:name] + @passenger = Passenger.find_by(name: passenger_name) + + redirect_to passenger_path(@passenger.id) + end + private def passenger_params diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 4275f53c7..55c1f245f 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,2 +1,36 @@ class TripsController < ApplicationController + def index + @trips = Trip.all + end + + def new + @trip = Trip.new + end + + def create +end + +def edit +end + + + def update + end + + def destroy + end + + private + +def trip_params + return params.require(:trip).permit(:cost, :rate) +end + +end + + + + + + end diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index f2d7a5600..35c17bb77 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,11 +1,6 @@

Drivers

-<%= form_tag by_name_path, method: :get do %> - <%= label_tag :name %> - <%= text_field_tag :name %> - <%= submit_tag %> -<% end %> - +<%= render partial: "shared/find_by_name", locals: {action_name: "Find Driver", url: by_name_path} %> <% @drivers.each do |driver| %>

<%= link_to "#{driver.name}", driver_path(driver.id) %>

<%end%> diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 5ec606402..7da6bea16 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,6 +1,8 @@

All Passengers

-<%# the first 50 part is temporary %> +<%= render partial: "shared/find_by_name", locals: {action_name: "Find Passenger", url: passenger_by_name_path} %> + + <% @passengers.each do |passenger| %>

<%= link_to passenger.name, passenger_path(passenger) %>

<% end %> diff --git a/app/views/shared/_find_by_name.html.erb b/app/views/shared/_find_by_name.html.erb new file mode 100644 index 000000000..34e6bdaf9 --- /dev/null +++ b/app/views/shared/_find_by_name.html.erb @@ -0,0 +1,6 @@ + +<%= form_tag url, method: :get do %> + <%= label_tag :name %> + <%= text_field_tag :name %> + <%= submit_tag action_name%> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 10e34381f..7dffdc8b8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,10 @@ get 'drivers/by_name', to: 'drivers#by_name', as: 'by_name' resources :drivers + resources :trips + +get 'passengers/by_name', to: 'passengers#by_name', as: 'passenger_by_name' resources :passengers resources :rideshare, only: [:index] From 91d16b5abe65dcad6ceb37c140062e9576f5f30a Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Tue, 3 Apr 2018 18:55:26 -0700 Subject: [PATCH 18/56] added nested routes for trip in passenger and driver --- app/controllers/trips_controller.rb | 40 ++++++++++++++--------------- app/views/drivers/show.html.erb | 2 ++ app/views/passengers/show.html.erb | 2 ++ app/views/trips/index.html.erb | 3 +++ config/routes.rb | 12 +++++---- 5 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 app/views/trips/index.html.erb diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 55c1f245f..1119963a6 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -1,6 +1,14 @@ class TripsController < ApplicationController def index - @trips = Trip.all + driver = params[:driver_id] + passenger = params[:passenger_id] + if driver + @trips = Trip.where(driver_id: driver) + elsif passenger + @trips = Trip.where(passenger_id: passenger) + else + @trips = Trip.all + end end def new @@ -8,29 +16,21 @@ def new end def create -end - -def edit -end - - - def update - end - - def destroy - end - - private - -def trip_params - return params.require(:trip).permit(:cost, :rate) -end - -end + end + def edit + end + def update + end + def destroy + end + private + def trip_params + return params.require(:trip).permit(:cost, :rate) + end end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 3a4f44217..db5782ba8 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -3,3 +3,5 @@

<%=@driver.name%>

ID : <%=@driver.id%>

VIN : <%=@driver.vin%>

+ +

<%= link_to 'See Trips', driver_trips_path(@driver) %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 70b7f4de6..c4bd76b67 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -3,3 +3,5 @@

<%= @passenger.name %>

ID : <%= @passenger.id %>

Phone #: <%= @passenger.phone_num %>

+ +

<%= link_to 'See Trips', passenger_trips_path(@passenger) %> diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb new file mode 100644 index 000000000..a94eb83af --- /dev/null +++ b/app/views/trips/index.html.erb @@ -0,0 +1,3 @@ +<% @trips.each do |trip| %> +

<%= trip.id %>

+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 7dffdc8b8..ad26dd009 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,13 +3,15 @@ root 'rideshare#index' get 'drivers/by_name', to: 'drivers#by_name', as: 'by_name' -resources :drivers - - -resources :trips +resources :drivers do + resources :trips, only: [:index] +end get 'passengers/by_name', to: 'passengers#by_name', as: 'passenger_by_name' -resources :passengers +resources :passengers do + resources :trips, only: [:index, :new] +end +resources :trips resources :rideshare, only: [:index] end From 57ca80ceb84a8f2536a0c233e0fc5878827524b9 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Tue, 3 Apr 2018 21:11:43 -0700 Subject: [PATCH 19/56] Added a link to edit and delete action for the drivers show vision --- app/controllers/drivers_controller.rb | 7 +++++++ app/views/drivers/show.html.erb | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 2ee66cb61..660cbea01 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -39,11 +39,18 @@ def update def by_name driver_name = params[:name] + @driver = Driver.find_by(name: driver_name) redirect_to driver_path(@driver.id) end + def destroy + Driver.destroy(params[:id]) + + redirect_to drivers_path + end + private def driver_params return params.require(:driver).permit(:name, :vin) diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index db5782ba8..412d873eb 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,7 +1,11 @@

Driver info:

<%=@driver.name%>

+

<%= link_to("Edit info", edit_driver_path(@driver.id)) %>

ID : <%=@driver.id%>

VIN : <%=@driver.vin%>

<%= link_to 'See Trips', driver_trips_path(@driver) %> +

+

+

<%= link_to("Delete", driver_path(@driver), method: :delete, data: {confirm: "Are you sure you want to delete #{@driver.name}?"}) %>

From 767be741c7a2a9522ff15752531434afd79218ad Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Tue, 3 Apr 2018 21:37:39 -0700 Subject: [PATCH 20/56] Added feature to be able to get into every of the drivers trips and view the info of each trip. --- app/controllers/drivers_controller.rb | 4 ++-- app/controllers/trips_controller.rb | 4 ++++ app/views/trips/index.html.erb | 3 ++- app/views/trips/show.html.erb | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 app/views/trips/show.html.erb diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 660cbea01..74534679a 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -30,7 +30,7 @@ def update the_driver.update_attributes(driver_params) if the_driver.save - redirect_to drivers_path + redirect_to driver_path(the_driver.id) end end @@ -42,7 +42,7 @@ def by_name @driver = Driver.find_by(name: driver_name) - redirect_to driver_path(@driver.id) + redirect_to driver_path(@driver) end def destroy diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 1119963a6..46cfdb0c3 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -15,6 +15,10 @@ def new @trip = Trip.new end + def show + @trip = Trip.find(params[:id]) + end + def create end diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb index a94eb83af..b778814be 100644 --- a/app/views/trips/index.html.erb +++ b/app/views/trips/index.html.erb @@ -1,3 +1,4 @@ <% @trips.each do |trip| %> -

<%= trip.id %>

+

<%= link_to trip.id, trip_path(trip)%>

+ <% end %> diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb new file mode 100644 index 000000000..05d226904 --- /dev/null +++ b/app/views/trips/show.html.erb @@ -0,0 +1,6 @@ + +

Trip <%= @trip.id%> Details:

+ +

Date : <%= @trip.date%>

+

Cost: $<%= @trip.cost%>

+

Rating: <%= @trip.rating%>

From 33e52e7c92104b82d7467eec69d4685e4da492f1 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Tue, 3 Apr 2018 21:42:36 -0700 Subject: [PATCH 21/56] fixed some of the trip show.html --- app/views/trips/index.html.erb | 1 - app/views/trips/show.html.erb | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb index b778814be..e0271f350 100644 --- a/app/views/trips/index.html.erb +++ b/app/views/trips/index.html.erb @@ -1,4 +1,3 @@ <% @trips.each do |trip| %>

<%= link_to trip.id, trip_path(trip)%>

- <% end %> diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index 05d226904..0de721220 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -4,3 +4,5 @@

Date : <%= @trip.date%>

Cost: $<%= @trip.cost%>

Rating: <%= @trip.rating%>

+

Driver: <%= @trip.driver_id%>

+

Passenger: <%= @trip.passenger_id%>

From 1e41bb9b29945de42bff711e49142f92d28ae3cd Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Tue, 3 Apr 2018 22:00:25 -0700 Subject: [PATCH 22/56] Added business logic to driver model, with a average_rating and earnings methods. Then I added them to the driver/show --- app/models/driver.rb | 19 +++++++++++++++++++ app/views/drivers/show.html.erb | 2 ++ 2 files changed, 21 insertions(+) diff --git a/app/models/driver.rb b/app/models/driver.rb index 197e65507..ce6d7ac5e 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -1,3 +1,22 @@ class Driver < ApplicationRecord has_many :trips + + def earnings + earnings = 0 + self.trips.each do |trip| + earnings += trip.cost + end + return earnings + end + + def average_rating + count = 0 + stars = 0 + self.trips.each do |trip| + count +=1 + stars += trip.rating + end + return stars/count + end + end diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 412d873eb..898ea474b 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -4,6 +4,8 @@

<%= link_to("Edit info", edit_driver_path(@driver.id)) %>

ID : <%=@driver.id%>

VIN : <%=@driver.vin%>

+

Total made in trips: $<%= @driver.earnings %>

+

Average rating: <%= @driver.average_rating%>

<%= link_to 'See Trips', driver_trips_path(@driver) %>

From 1531b56856b7e3fe74d3caeb0eef7d25040fed6d Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Tue, 3 Apr 2018 22:09:22 -0700 Subject: [PATCH 23/56] added a total spent method to passenger, added to passenger view --- app/controllers/drivers_controller.rb | 2 -- app/controllers/passengers_controller.rb | 2 +- app/models/passenger.rb | 8 ++++++++ app/views/passengers/show.html.erb | 5 +++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 74534679a..2e3a0f969 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -35,8 +35,6 @@ def update end end - # don't forget delete - def by_name driver_name = params[:name] diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 62f191819..87e2d377e 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -39,7 +39,7 @@ def update end end - def delete + def destroy Passenger.destroy(params[:id]) end diff --git a/app/models/passenger.rb b/app/models/passenger.rb index 2fef89192..ab8b6707d 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,3 +1,11 @@ class Passenger < ApplicationRecord has_many :trips + + def total_spent + total = 0.00 + trips.each do |trip| + total += trip.cost + end + return total.round(2) + end end diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index c4bd76b67..21f889cfd 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,7 +1,12 @@

Passenger info:

<%= @passenger.name %>

+

<%= link_to("Edit info", edit_passenger_path(@passenger.id)) %>

ID : <%= @passenger.id %>

Phone #: <%= @passenger.phone_num %>

+

Total Spent: $<%= @passenger.total_spent %>

<%= link_to 'See Trips', passenger_trips_path(@passenger) %> +

+

+

<%= link_to("Delete", passenger_path(@passenger), method: :delete, data: {confirm: "Are you sure you want to delete #{@passenger.name}?"}) %>

From 52da0611b374896189997779094aa77d5bf82a0e Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Wed, 4 Apr 2018 12:47:22 -0700 Subject: [PATCH 24/56] passenger can request a new trip and rating will update on page if submitted --- app/controllers/trips_controller.rb | 28 ++++++++++++++++++++++++---- app/views/passengers/show.html.erb | 2 ++ app/views/trips/show.html.erb | 16 +++++++++++++--- config/routes.rb | 2 +- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 46cfdb0c3..09f3ab41e 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -11,21 +11,41 @@ def index end end - def new - @trip = Trip.new - end - def show @trip = Trip.find(params[:id]) + @driver = Driver.find(@trip.driver_id) + @passenger = Passenger.find(@trip.passenger_id) + end + + def new + @trip = Trip.new(passenger_id: params[:passenger_id]) end + def create + driver = Driver.all.sample + @trip = Trip.new(passenger_id: params[:passenger_id], driver_id: driver.id) + @trip.date = Date.today + cost = (1000..5000).to_a.sample + @trip.cost = cost/100.00 + + if @trip.save + redirect_to trip_path(@trip) + else + redirect_to passenger_path(@trip.passenger_id) + end + end def edit end def update + @trip = Trip.find(params[:id]) + @trip.rating = params[:trip][:rating] + + @trip.save + redirect_to trip_path(@trip) end def destroy diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 21f889cfd..596ba66ed 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -7,6 +7,8 @@

Total Spent: $<%= @passenger.total_spent %>

<%= link_to 'See Trips', passenger_trips_path(@passenger) %> + +

<%= link_to 'Request Trip', passenger_trips_path(@passenger), method: :post %>



<%= link_to("Delete", passenger_path(@passenger), method: :delete, data: {confirm: "Are you sure you want to delete #{@passenger.name}?"}) %>

diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index 0de721220..a77231ceb 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -3,6 +3,16 @@

Date : <%= @trip.date%>

Cost: $<%= @trip.cost%>

-

Rating: <%= @trip.rating%>

-

Driver: <%= @trip.driver_id%>

-

Passenger: <%= @trip.passenger_id%>

+

+ <% if @trip.rating.nil? %> + <%= form_for @trip do |f| %> + <%= f.label :rating %> + <%= f.number_field :rating %> + <%= f.submit 'Rate' %> + <% end %> + <% else %> + Rating: <%= @trip.rating %> + <% end %> +

+

Driver: <%= @driver.name %>

+

Passenger: <%= @passenger.name %>

diff --git a/config/routes.rb b/config/routes.rb index ad26dd009..3ee5e6206 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,7 @@ get 'passengers/by_name', to: 'passengers#by_name', as: 'passenger_by_name' resources :passengers do - resources :trips, only: [:index, :new] + resources :trips, only: [:index, :new, :create] end resources :trips From 66fc74129936ccfe58eb94b5cf91c3f896a36394 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Wed, 4 Apr 2018 15:27:13 -0700 Subject: [PATCH 25/56] rounded assigned cost of trip to 2 decimal places --- app/controllers/trips_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 09f3ab41e..91d0964b2 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -27,7 +27,7 @@ def create @trip = Trip.new(passenger_id: params[:passenger_id], driver_id: driver.id) @trip.date = Date.today cost = (1000..5000).to_a.sample - @trip.cost = cost/100.00 + @trip.cost = (cost/100.00).round(2) if @trip.save redirect_to trip_path(@trip) From e3fe1715fc429ccaaf6ba1863512d9124366c582 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Wed, 4 Apr 2018 15:37:34 -0700 Subject: [PATCH 26/56] Added a link in layout view to create a new passenger and driver --- app/views/layouts/application.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9cfe6e808..18296bab7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,7 +13,9 @@
From 472a4bdfbd870bcd9d646106d783f6707a211d1c Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Wed, 4 Apr 2018 19:46:45 -0700 Subject: [PATCH 27/56] Added feature to the partial by_name to require that the text field cant be black to be able to submit --- app/views/shared/_find_by_name.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/_find_by_name.html.erb b/app/views/shared/_find_by_name.html.erb index 34e6bdaf9..e0eb664c6 100644 --- a/app/views/shared/_find_by_name.html.erb +++ b/app/views/shared/_find_by_name.html.erb @@ -1,6 +1,6 @@ <%= form_tag url, method: :get do %> <%= label_tag :name %> - <%= text_field_tag :name %> + <%= text_field_tag :name, params[:name], required: true%> <%= submit_tag action_name%> <% end %> From 84ac7c446e0b134dafabdbc67e6391b46fee7d11 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Wed, 4 Apr 2018 19:52:31 -0700 Subject: [PATCH 28/56] If driver or passenger not found in serch, on index view, it will redirect to the same page --- app/controllers/drivers_controller.rb | 6 +++++- app/controllers/passengers_controller.rb | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 2e3a0f969..2372e5941 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -40,7 +40,11 @@ def by_name @driver = Driver.find_by(name: driver_name) - redirect_to driver_path(@driver) + if @driver == nil + redirect_to drivers_path + else + redirect_to driver_path(@driver) + end end def destroy diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 87e2d377e..b58404d8c 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -47,7 +47,12 @@ def by_name passenger_name = params[:name] @passenger = Passenger.find_by(name: passenger_name) - redirect_to passenger_path(@passenger.id) + if @passenger == nil + redirect_to passengers_path + else + + redirect_to passenger_path(@passenger.id) + end end private From 004b04df9aa53e849c8b790d6852acbae4cbe94a Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Wed, 4 Apr 2018 20:30:22 -0700 Subject: [PATCH 29/56] updated driver calculate earnings and average rating to deal with nil cases and updated driver#destroy to replace the driver in its trips with a placeholder driver before destroying the selected driver --- app/controllers/drivers_controller.rb | 10 ++++++++-- app/controllers/trips_controller.rb | 3 +-- app/models/driver.rb | 3 +++ app/models/trip.rb | 9 +++++++++ app/views/drivers/index.html.erb | 4 +++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 2e3a0f969..735c47a1f 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -44,12 +44,18 @@ def by_name end def destroy - Driver.destroy(params[:id]) + no_driver = Driver.find(9999) - redirect_to drivers_path + Trip.replace_deleted_driver(params[:id], no_driver) + + Driver.destroy(params[:id]) + + redirect_to drivers_path end + private + def driver_params return params.require(:driver).permit(:name, :vin) end diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 91d0964b2..3f73fbe62 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -37,8 +37,7 @@ def create end - def edit - end + def edit; end def update @trip = Trip.find(params[:id]) diff --git a/app/models/driver.rb b/app/models/driver.rb index ce6d7ac5e..6d80b4da5 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -4,6 +4,7 @@ class Driver < ApplicationRecord def earnings earnings = 0 self.trips.each do |trip| + next if trip.cost.nil? earnings += trip.cost end return earnings @@ -12,7 +13,9 @@ def earnings def average_rating count = 0 stars = 0 + return 0 if trips.empty? self.trips.each do |trip| + next if trip.rating.nil? count +=1 stars += trip.rating end diff --git a/app/models/trip.rb b/app/models/trip.rb index 8e2566cd8..162aa6109 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,4 +1,13 @@ class Trip < ApplicationRecord belongs_to :driver belongs_to :passenger + + def self.replace_deleted_driver(driver_id, replacement) + trips = Trip.where(driver_id: driver_id) + + trips.each do |trip| + trip.driver = replacement + trip.save + end + end end diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 35c17bb77..e5c9dd6c6 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,6 +1,8 @@

Drivers

-<%= render partial: "shared/find_by_name", locals: {action_name: "Find Driver", url: by_name_path} %> +<%= render partial: "shared/find_by_name", locals: {action_name: "Find Driver", url: by_name_path} %> + + <% @drivers.each do |driver| %>

<%= link_to "#{driver.name}", driver_path(driver.id) %>

<%end%> From fce06bd0d93a141da24a1aae63f763cee8effe83 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Wed, 4 Apr 2018 21:15:53 -0700 Subject: [PATCH 30/56] minor css changes --- app/assets/stylesheets/application.css | 5 +++++ app/views/layouts/application.html.erb | 2 ++ app/views/rideshare/index.html.erb | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f51..1dfc665d9 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,8 @@ *= require_tree . *= require_self */ + +body { + font-family: 'Dosis', sans-serif; + +} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 18296bab7..55aa42f10 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,6 +6,8 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + diff --git a/app/views/rideshare/index.html.erb b/app/views/rideshare/index.html.erb index 3d536a409..4bcd9886f 100644 --- a/app/views/rideshare/index.html.erb +++ b/app/views/rideshare/index.html.erb @@ -1,4 +1,15 @@ -

Welcome to our Rideshare App

+
+
+
+

+ Welcome to our Rideshare App! +

+

+ This is a subtitle +

+
+
+
<%= link_to 'For Drivers', drivers_path %>

From eb5f1707907f120eed2911d87dd6a9c2378d569e Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Thu, 5 Apr 2018 09:06:56 -0700 Subject: [PATCH 31/56] added list of trips to passenger show page --- app/views/drivers/index.html.erb | 2 +- app/views/passengers/index.html.erb | 2 +- app/views/passengers/show.html.erb | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index e5c9dd6c6..4cfecbe38 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -5,4 +5,4 @@ <% @drivers.each do |driver| %>

<%= link_to "#{driver.name}", driver_path(driver.id) %>

-<%end%> +<% end %> diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 7da6bea16..cf25b2123 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,6 +1,6 @@

All Passengers

-<%= render partial: "shared/find_by_name", locals: {action_name: "Find Passenger", url: passenger_by_name_path} %> +<%= render partial: "shared/find_by_name", locals: {action_name: "Find Passenger", url: passenger_by_name_path} %> <% @passengers.each do |passenger| %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 596ba66ed..0aa417a79 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -6,7 +6,21 @@

Phone #: <%= @passenger.phone_num %>

Total Spent: $<%= @passenger.total_spent %>

-

<%= link_to 'See Trips', passenger_trips_path(@passenger) %> +
+

Trips:

+
    + <% @passenger.trips.each do |trip| %> +
  • + <%= link_to trip.id, trip_path(trip) %> + <%= trip.date %> + <%= trip.driver.name %> + <%= trip.rating %> + <%= trip.cost %> +
  • + <% end %> +
+ +

<%= link_to 'Request Trip', passenger_trips_path(@passenger), method: :post %>

From 46dd07a0878b5bfa643bac6254343354dc807d3e Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Thu, 5 Apr 2018 13:31:50 -0700 Subject: [PATCH 32/56] added list of trips to passenger and driver page, created a partial for displaying trips --- app/assets/stylesheets/application.css | 14 ++++++++++++++ app/views/drivers/show.html.erb | 7 ++++--- app/views/passengers/show.html.erb | 17 ++++------------- app/views/shared/_display_trips.html.erb | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 app/views/shared/_display_trips.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 1dfc665d9..e865de561 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -18,3 +18,17 @@ body { font-family: 'Dosis', sans-serif; } + +.display-trips { + display: flex; + flex-wrap: nowrap; + justify-content: space-around; + width: 70vw; + align-content: center; + /*border: solid thin black;*/ +} + +.display-trips > li { + text-align: center; + width: 12vw; +} diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 898ea474b..041792113 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -7,7 +7,8 @@

Total made in trips: $<%= @driver.earnings %>

Average rating: <%= @driver.average_rating%>

-

<%= link_to 'See Trips', driver_trips_path(@driver) %> -

-

+

+<%= render partial: 'shared/display_trips', locals: {model: @driver, pass_driver: 'Passenger'} %> + +

<%= link_to("Delete", driver_path(@driver), method: :delete, data: {confirm: "Are you sure you want to delete #{@driver.name}?"}) %>

diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 0aa417a79..386cb5a5c 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -7,22 +7,13 @@

Total Spent: $<%= @passenger.total_spent %>


-

Trips:

-
    - <% @passenger.trips.each do |trip| %> -
  • - <%= link_to trip.id, trip_path(trip) %> - <%= trip.date %> - <%= trip.driver.name %> - <%= trip.rating %> - <%= trip.cost %> -
  • - <% end %> -
+

<%= link_to 'Request Trip', passenger_trips_path(@passenger), method: :post %> +
+ +<%= render partial: 'shared/display_trips', locals: {model: @passenger, pass_driver: 'Driver'} %>
-

<%= link_to 'Request Trip', passenger_trips_path(@passenger), method: :post %>



<%= link_to("Delete", passenger_path(@passenger), method: :delete, data: {confirm: "Are you sure you want to delete #{@passenger.name}?"}) %>

diff --git a/app/views/shared/_display_trips.html.erb b/app/views/shared/_display_trips.html.erb new file mode 100644 index 000000000..05cb30e7b --- /dev/null +++ b/app/views/shared/_display_trips.html.erb @@ -0,0 +1,22 @@ +

Trips:

+
    +
  • ID
  • +
  • Date
  • +
  • <%= pass_driver %> Name
  • +
  • Rating
  • +
  • Cost
  • +
+ <% model.trips.each do |trip| %> +
    +
  • <%= link_to trip.id, trip_path(trip) %>
  • +
  • <%= trip.date %>
  • + <% if model == @passenger %> +
  • <%= trip.driver.name %>
  • + <% else %> +
  • <%= trip.passenger.name %>
  • + <% end %> +
  • <%= trip.rating %>
  • +
  • <%= trip.cost %>
  • +
+ <% end %> + From 8a4a999e20546c55b878b948a413fe79eded4d51 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Thu, 5 Apr 2018 14:26:46 -0700 Subject: [PATCH 33/56] minor css changes --- app/assets/stylesheets/application.css | 5 ++--- app/views/drivers/show.html.erb | 2 +- app/views/passengers/show.html.erb | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index e865de561..45e6a84f3 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -23,12 +23,11 @@ body { display: flex; flex-wrap: nowrap; justify-content: space-around; - width: 70vw; + min-width: 70vw; align-content: center; - /*border: solid thin black;*/ } .display-trips > li { text-align: center; - width: 12vw; + min-width: 12vw; } diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 041792113..851ca69c6 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -11,4 +11,4 @@ <%= render partial: 'shared/display_trips', locals: {model: @driver, pass_driver: 'Passenger'} %>

-

<%= link_to("Delete", driver_path(@driver), method: :delete, data: {confirm: "Are you sure you want to delete #{@driver.name}?"}) %>

+

<%= link_to("Delete Driver", driver_path(@driver), method: :delete, data: {confirm: "Are you sure you want to delete #{@driver.name}?"}) %>

diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 386cb5a5c..4d56ea30d 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -16,4 +16,4 @@



-

<%= link_to("Delete", passenger_path(@passenger), method: :delete, data: {confirm: "Are you sure you want to delete #{@passenger.name}?"}) %>

+

<%= link_to("Delete Passenger", passenger_path(@passenger), method: :delete, data: {confirm: "Are you sure you want to delete #{@passenger.name}?"}) %>

From 566a3772992ff73aab0ec586abded95369cdcab3 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Thu, 5 Apr 2018 15:22:42 -0700 Subject: [PATCH 34/56] validation and display error messages --- app/controllers/drivers_controller.rb | 19 ++++++++++++------- app/controllers/passengers_controller.rb | 5 ++--- app/models/driver.rb | 2 ++ app/models/passenger.rb | 2 ++ app/models/trip.rb | 1 + app/views/drivers/_form.html.erb | 7 +++++++ app/views/passengers/_form.html.erb | 6 ++++++ 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index f9a027d3b..ffaaec01b 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -13,9 +13,11 @@ def show end def create - new_driver = Driver.new(driver_params) - if new_driver.save - redirect_to driver_path(new_driver.id) + @driver = Driver.new(driver_params) + if @driver.save + redirect_to driver_path(@driver.id) + else + render :new end end @@ -26,11 +28,13 @@ def edit def update - the_driver = Driver.find(params[:id]) - the_driver.update_attributes(driver_params) + @driver = Driver.find(params[:id]) + @driver.update_attributes(driver_params) - if the_driver.save - redirect_to driver_path(the_driver.id) + if @driver.save + redirect_to driver_path(@driver.id) + else + render :edit end end @@ -41,6 +45,7 @@ def by_name @driver = Driver.find_by(name: driver_name) if @driver == nil + #flash.now[:error] = "Driver not found" redirect_to drivers_path else redirect_to driver_path(@driver) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index b58404d8c..acabb01ae 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -9,13 +9,12 @@ def new end def create - @passenger = Passenger.find(params[:id]) - @passenger.new(passenger_params) + @passenger = Passenger.new(passenger_params) if @passenger.save redirect_to passengers_path else - render :edit + render :new end end diff --git a/app/models/driver.rb b/app/models/driver.rb index 6d80b4da5..a5f5e8e01 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -1,5 +1,7 @@ class Driver < ApplicationRecord has_many :trips + validates :name, presence: true + validates :vin, presence: true def earnings earnings = 0 diff --git a/app/models/passenger.rb b/app/models/passenger.rb index ab8b6707d..c0e082d86 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -1,5 +1,7 @@ class Passenger < ApplicationRecord has_many :trips + validates :name, presence: true + validates :phone_num, presence: true def total_spent total = 0.00 diff --git a/app/models/trip.rb b/app/models/trip.rb index 162aa6109..a50de7548 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,6 +1,7 @@ class Trip < ApplicationRecord belongs_to :driver belongs_to :passenger + validates :rating, on: :update ,numericality: {greater_than_or_equal_to: 1, less_than_or_equal_to: 5 } def self.replace_deleted_driver(driver_id, replacement) trips = Trip.where(driver_id: driver_id) diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb index e9171da4c..350d28613 100644 --- a/app/views/drivers/_form.html.erb +++ b/app/views/drivers/_form.html.erb @@ -1,6 +1,13 @@

<%= page_title %>

+<% if @driver.errors.any?%> +<% @driver.errors.each do |column, message|%> +<%= column%> - <%= message %> +<%end%> +<%end%> + + <%= form_for @driver do |f| %> <%= f.label :name %> <%= f.text_field :name %> diff --git a/app/views/passengers/_form.html.erb b/app/views/passengers/_form.html.erb index 506430064..709dabaee 100644 --- a/app/views/passengers/_form.html.erb +++ b/app/views/passengers/_form.html.erb @@ -2,6 +2,12 @@ <%= page_title %> +<% if @passenger.errors.any?%> +<% @passenger.errors.each do |column, message|%> +<%= column%> - <%= message %> +<%end%> +<%end%> + <%= form_for @passenger do |f| %> <%= f.label :name %> <%= f.text_field :name %> From bafc2b720fa04f53c046ccacbde88fdc55567166 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Thu, 5 Apr 2018 15:30:28 -0700 Subject: [PATCH 35/56] added before action to create driver 9999 when destroying a driver --- app/controllers/drivers_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index ffaaec01b..28a163eb7 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -1,4 +1,5 @@ class DriversController < ApplicationController + before_action :create_driver9999, only: [:destroy] def index @drivers = Driver.all @@ -68,4 +69,8 @@ def destroy def driver_params return params.require(:driver).permit(:name, :vin) end + + def create_driver9999 + return Driver.create(id: 9999, name: 'Driver no longer exists', vin: '') + end end From 12eb9a87957448aef14169e0a3484a4168104217 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Thu, 5 Apr 2018 15:33:42 -0700 Subject: [PATCH 36/56] updated destroy driver --- app/controllers/drivers_controller.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 28a163eb7..ce7fa6317 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -1,5 +1,4 @@ class DriversController < ApplicationController - before_action :create_driver9999, only: [:destroy] def index @drivers = Driver.all @@ -54,7 +53,8 @@ def by_name end def destroy - no_driver = Driver.find(9999) + no_driver = Driver.create(id: 9999, name: 'Driver no longer exists', vin: '') + # no_driver = Driver.find(9999) Trip.replace_deleted_driver(params[:id], no_driver) @@ -69,8 +69,4 @@ def destroy def driver_params return params.require(:driver).permit(:name, :vin) end - - def create_driver9999 - return Driver.create(id: 9999, name: 'Driver no longer exists', vin: '') - end end From d4e5eb09530328d7224d4151c8932ec5a0e644da Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Thu, 5 Apr 2018 15:59:02 -0700 Subject: [PATCH 37/56] Tried make foreign keys take nil --- app/controllers/drivers_controller.rb | 8 ++++---- app/models/trip.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index ce7fa6317..163e00713 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -53,10 +53,10 @@ def by_name end def destroy - no_driver = Driver.create(id: 9999, name: 'Driver no longer exists', vin: '') - # no_driver = Driver.find(9999) - - Trip.replace_deleted_driver(params[:id], no_driver) + # no_driver = Driver.create(id: 9999, name: 'Driver no longer exists', vin: '') + # # no_driver = Driver.find(9999) + # + # Trip.replace_deleted_driver(params[:id], no_driver) Driver.destroy(params[:id]) diff --git a/app/models/trip.rb b/app/models/trip.rb index a50de7548..43cd02686 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,6 +1,6 @@ class Trip < ApplicationRecord - belongs_to :driver - belongs_to :passenger + belongs_to :driver, optional: true + belongs_to :passenger, optional: true validates :rating, on: :update ,numericality: {greater_than_or_equal_to: 1, less_than_or_equal_to: 5 } def self.replace_deleted_driver(driver_id, replacement) From 8caad4c03d6bde5c254d16cda9c0da5dc079060f Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Thu, 5 Apr 2018 17:53:48 -0700 Subject: [PATCH 38/56] made a column in Driver and Passenger that is toggleable for disabled or not --- app/controllers/drivers_controller.rb | 18 +++++++++--------- app/controllers/passengers_controller.rb | 13 +++++++++---- app/models/trip.rb | 12 ++---------- db/schema.rb | 4 +++- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 163e00713..885eefd4e 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -1,7 +1,7 @@ class DriversController < ApplicationController def index - @drivers = Driver.all + @drivers = Driver.where(disabled: false) end def new @@ -42,7 +42,7 @@ def update def by_name driver_name = params[:name] - @driver = Driver.find_by(name: driver_name) + @driver = Driver.where(disabled: false).find_by(name: driver_name) if @driver == nil #flash.now[:error] = "Driver not found" @@ -53,14 +53,14 @@ def by_name end def destroy - # no_driver = Driver.create(id: 9999, name: 'Driver no longer exists', vin: '') - # # no_driver = Driver.find(9999) - # - # Trip.replace_deleted_driver(params[:id], no_driver) - Driver.destroy(params[:id]) - - redirect_to drivers_path + driver = Driver.find(params[:id]) + driver.disabled = true + if driver.save + redirect_to drivers_path + else + redirect_to driver_path(driver) + end end diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index acabb01ae..576d302f0 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -1,7 +1,7 @@ class PassengersController < ApplicationController def index - @passengers = Passenger.all + @passengers = Passenger.where(disabled: false) end def new @@ -39,17 +39,22 @@ def update end def destroy - Passenger.destroy(params[:id]) + passenger = Passenger.find(params[:id]) + passenger.disabled = true + if passenger.save + redirect_to passengers_path + else + redirect_to passenger_path(passenger) + end end def by_name passenger_name = params[:name] - @passenger = Passenger.find_by(name: passenger_name) + @passenger = Passenger.where(disabled: false).find_by(name: passenger_name) if @passenger == nil redirect_to passengers_path else - redirect_to passenger_path(@passenger.id) end end diff --git a/app/models/trip.rb b/app/models/trip.rb index 43cd02686..f29ba163a 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,14 +1,6 @@ class Trip < ApplicationRecord - belongs_to :driver, optional: true - belongs_to :passenger, optional: true + belongs_to :driver + belongs_to :passenger validates :rating, on: :update ,numericality: {greater_than_or_equal_to: 1, less_than_or_equal_to: 5 } - def self.replace_deleted_driver(driver_id, replacement) - trips = Trip.where(driver_id: driver_id) - - trips.each do |trip| - trip.driver = replacement - trip.save - end - end end diff --git a/db/schema.rb b/db/schema.rb index 85b89887e..c502c5ceb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180402234723) do +ActiveRecord::Schema.define(version: 20180405225954) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,7 @@ t.string "vin" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "disabled", default: false end create_table "passengers", force: :cascade do |t| @@ -27,6 +28,7 @@ t.string "phone_num" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "disabled", default: false end create_table "trips", force: :cascade do |t| From bc42545893a3ea7784d300cef3183124d4a08998 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Thu, 5 Apr 2018 18:51:01 -0700 Subject: [PATCH 39/56] uploading the file for disabled column and some css updates --- app/assets/stylesheets/application.css | 9 +++++++++ app/views/drivers/_form.html.erb | 17 ++++++++-------- app/views/drivers/index.html.erb | 20 ++++++++++++++++--- .../20180405225954_add_disabled_column.rb | 6 ++++++ 4 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20180405225954_add_disabled_column.rb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 45e6a84f3..ac676ff3c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -31,3 +31,12 @@ body { text-align: center; min-width: 12vw; } + +.show-page { + display: grid; + grid-template-columns: 1fr 1fr; +} + +.show-page li { + text-align: center; +} diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb index 350d28613..96fdb82a8 100644 --- a/app/views/drivers/_form.html.erb +++ b/app/views/drivers/_form.html.erb @@ -1,18 +1,19 @@

<%= page_title %>

+ <% if @driver.errors.any?%> -<% @driver.errors.each do |column, message|%> -<%= column%> - <%= message %> -<%end%> + <% @driver.errors.each do |column, message|%> + <%= column %> - <%= message %> + <%end%> <%end%> <%= form_for @driver do |f| %> -<%= f.label :name %> -<%= f.text_field :name %> + <%= f.label :name %> + <%= f.text_field :name %> -<%= f.label :vin %> -<%= f.text_field :vin %> -<%= f.submit action_name %> + <%= f.label :vin %> + <%= f.text_field :vin %> + <%= f.submit action_name %> <% end %> diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 4cfecbe38..5bc1c29e2 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,8 +1,22 @@

Drivers

+

Find by Name

<%= render partial: "shared/find_by_name", locals: {action_name: "Find Driver", url: by_name_path} %> +
    +
  • Name
  • +
  • Rating
  • +
-<% @drivers.each do |driver| %> -

<%= link_to "#{driver.name}", driver_path(driver.id) %>

-<% end %> +
+
    + <% @drivers.each do |driver| %> +
  • + <%= link_to "#{driver.name}", driver_path(driver.id) %> +
  • +
  • + <%= driver.average_rating %> +
  • + <% end %> +
      +
diff --git a/db/migrate/20180405225954_add_disabled_column.rb b/db/migrate/20180405225954_add_disabled_column.rb new file mode 100644 index 000000000..ce8973174 --- /dev/null +++ b/db/migrate/20180405225954_add_disabled_column.rb @@ -0,0 +1,6 @@ +class AddDisabledColumn < ActiveRecord::Migration[5.1] + def change + add_column :drivers, :disabled, :boolean, default: false + add_column :passengers, :disabled, :boolean, default: false + end +end From 3c771fc2cf1f171e0025f2776f2d009314471d85 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 01:09:32 -0700 Subject: [PATCH 40/56] Added feature when finding a driver for a new trip to choose the one that has the longest time with no tripss --- app/controllers/trips_controller.rb | 17 +++++++++++++-- app/models/driver.rb | 32 +++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 3f73fbe62..5d19dc3bb 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -23,8 +23,21 @@ def new def create - driver = Driver.all.sample - @trip = Trip.new(passenger_id: params[:passenger_id], driver_id: driver.id) + drivers = Driver.where(disabled: false) + longest_driver_not_driving = nil + drivers.each do |driver| + if driver.trips.empty? || driver.last_trip.date == nil + longest_driver_not_driving = driver + elsif longest_driver_not_driving == nil || longest_driver_not_driving.trips.empty? + longest_driver_not_driving = driver + else + if longest_driver_not_driving.last_trip.date > driver.last_trip.date + longest_driver_not_driving = driver + end + end + end + + @trip = Trip.new(passenger_id: params[:passenger_id], driver_id: longest_driver_not_driving.id) @trip.date = Date.today cost = (1000..5000).to_a.sample @trip.cost = (cost/100.00).round(2) diff --git a/app/models/driver.rb b/app/models/driver.rb index a5f5e8e01..ed4dca596 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -5,10 +5,10 @@ class Driver < ApplicationRecord def earnings earnings = 0 - self.trips.each do |trip| - next if trip.cost.nil? - earnings += trip.cost - end + self.trips.each do |trip| + next if trip.cost.nil? + earnings += trip.cost + end return earnings end @@ -24,4 +24,28 @@ def average_rating return stars/count end + def last_trip + drivers_trips = self.trips.order(date: :desc) + if drivers_trips.length == 0 + nil + end + return drivers_trips.first + end + + def the_driver + longest_driver_not_driving = nil + drivers = Driver.where(disabled: false) + drivers.each do |driver| + if longest_driver_not_driving == nil + longest_driver_not_driving = driver + else + if longest_driver_not_driving.last_trip.date > driver.last_trip.date + longest_driver_not_driving = driver + end + end + return longest_driver_not_driving + end + + + end end From 5c5dc7cc481e31392158b4137061ea30e565e1af Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 11:58:10 -0700 Subject: [PATCH 41/56] Added a bussiness logig method to check if the driver is on trip, assuming that if there is a trip with no rating is still in trip --- app/controllers/trips_controller.rb | 14 ++++++++------ app/models/driver.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 5d19dc3bb..de972a87f 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -26,13 +26,15 @@ def create drivers = Driver.where(disabled: false) longest_driver_not_driving = nil drivers.each do |driver| - if driver.trips.empty? || driver.last_trip.date == nil - longest_driver_not_driving = driver - elsif longest_driver_not_driving == nil || longest_driver_not_driving.trips.empty? - longest_driver_not_driving = driver - else - if longest_driver_not_driving.last_trip.date > driver.last_trip.date + unless driver.driver_on_trip + if driver.trips.empty? || driver.last_trip.date == nil longest_driver_not_driving = driver + elsif longest_driver_not_driving == nil || longest_driver_not_driving.trips.empty? + longest_driver_not_driving = driver + else + if longest_driver_not_driving.last_trip.date > driver.last_trip.date + longest_driver_not_driving = driver + end end end end diff --git a/app/models/driver.rb b/app/models/driver.rb index ed4dca596..d5a424ccf 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -45,7 +45,15 @@ def the_driver end return longest_driver_not_driving end + end - + def driver_on_trip + self.trips.each do |trip| + return true if trip.rating == nil + end + return false end + + + end From 71393ebed2aaaba0189f5d41fdbd4233cf124c0b Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 12:07:39 -0700 Subject: [PATCH 42/56] added some ideas for business logic in driver model for finding available driver, added some styling to driver page --- app/models/driver.rb | 27 +++++++++++++++++++++++++ app/views/drivers/index.html.erb | 14 ++++++++++--- app/views/shared/_find_by_name.html.erb | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index a5f5e8e01..da7003019 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -24,4 +24,31 @@ def average_rating return stars/count end + def last_trips + ended_trips = self.trips.where.not(updated_at: nil) + return ended_trips.max_by {|trip| trip.updated_at } + end + + def check_if_no_trips + active_drivers = Driver.where(disabled: false) + drivers_with_no_trips = active_drivers.select {|driver| driver.trips.empty?} + + if !drivers_with_no_trips.empty? + return drivers_with_no_trips.first + end + + return active_drivers + end + + def get_last_driver + trips_or_driver = check_if_no_trips + + if trips_or_driver.length > 1 + last_trips = trips_or_driver.map {|driver| driver.last_trip} + last_trip = last_trips.order(:updated_at).first + + return last_trip + end + return trips_or_driver + end end diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 5bc1c29e2..a31138424 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -1,7 +1,15 @@ -

Drivers

+
+
+
+

+ Drivers +

+

Find by Name

+ <%= render partial: "shared/find_by_name", locals: {action_name: "Find Driver", url: by_name_path} %> +
+
+
-

Find by Name

-<%= render partial: "shared/find_by_name", locals: {action_name: "Find Driver", url: by_name_path} %>
  • Name
  • diff --git a/app/views/shared/_find_by_name.html.erb b/app/views/shared/_find_by_name.html.erb index e0eb664c6..7cc027b37 100644 --- a/app/views/shared/_find_by_name.html.erb +++ b/app/views/shared/_find_by_name.html.erb @@ -2,5 +2,5 @@ <%= form_tag url, method: :get do %> <%= label_tag :name %> <%= text_field_tag :name, params[:name], required: true%> - <%= submit_tag action_name%> + <%= button_tag action_name, class: 'button is-primary is-outlined is-inverted is-small' %> <% end %> From 44e48f6c514ab9dd13f83ada987b4e8296728d2e Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 12:29:38 -0700 Subject: [PATCH 43/56] Was able to move the ugly code from controller to the driver model --- app/controllers/trips_controller.rb | 18 ++---------------- app/models/driver.rb | 18 +++++++++++------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index de972a87f..5030b9f76 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -23,23 +23,9 @@ def new def create - drivers = Driver.where(disabled: false) - longest_driver_not_driving = nil - drivers.each do |driver| - unless driver.driver_on_trip - if driver.trips.empty? || driver.last_trip.date == nil - longest_driver_not_driving = driver - elsif longest_driver_not_driving == nil || longest_driver_not_driving.trips.empty? - longest_driver_not_driving = driver - else - if longest_driver_not_driving.last_trip.date > driver.last_trip.date - longest_driver_not_driving = driver - end - end - end - end - @trip = Trip.new(passenger_id: params[:passenger_id], driver_id: longest_driver_not_driving.id) + driver = Driver.the_driver + @trip = Trip.new(passenger_id: params[:passenger_id], driver_id: driver.id) @trip.date = Date.today cost = (1000..5000).to_a.sample @trip.cost = (cost/100.00).round(2) diff --git a/app/models/driver.rb b/app/models/driver.rb index d5a424ccf..c062fc446 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -32,19 +32,23 @@ def last_trip return drivers_trips.first end - def the_driver - longest_driver_not_driving = nil + def self.the_driver drivers = Driver.where(disabled: false) + longest_driver_not_driving = Driver.first drivers.each do |driver| - if longest_driver_not_driving == nil - longest_driver_not_driving = driver - else - if longest_driver_not_driving.last_trip.date > driver.last_trip.date + unless driver.driver_on_trip + if driver.trips.empty? || driver.last_trip.date == nil longest_driver_not_driving = driver + elsif longest_driver_not_driving == nil || longest_driver_not_driving.trips.empty? + longest_driver_not_driving = driver + else + if longest_driver_not_driving.last_trip.date > driver.last_trip.date + longest_driver_not_driving = driver + end end end - return longest_driver_not_driving end + return longest_driver_not_driving end def driver_on_trip From 4259cc66f55a1589a3e3ae23fcb7cf9459aed2fb Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 13:03:43 -0700 Subject: [PATCH 44/56] added page stylings and if rating is incomplete on driver and passenger show page, will display a form to get rating --- app/assets/stylesheets/application.css | 11 +++++-- app/views/drivers/index.html.erb | 40 ++++++++++++++---------- app/views/layouts/application.html.erb | 14 ++++----- app/views/passengers/index.html.erb | 15 ++++++--- app/views/rideshare/index.html.erb | 11 +++---- app/views/shared/_display_trips.html.erb | 12 ++++++- 6 files changed, 66 insertions(+), 37 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ac676ff3c..5a7a3ead4 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -16,10 +16,17 @@ body { font-family: 'Dosis', sans-serif; +} + +.navbar-item a { + color: white; +} +.navbar-item a:hover { + color: rgb(49, 213, 193); } -.display-trips { +/*.display-trips { display: flex; flex-wrap: nowrap; justify-content: space-around; @@ -30,7 +37,7 @@ body { .display-trips > li { text-align: center; min-width: 12vw; -} +}*/ .show-page { display: grid; diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index a31138424..bb633eaf1 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -11,20 +11,28 @@ -
      -
    • Name
    • -
    • Rating
    • -
    + + + +
      +
    • Name
    • +
    • Rating
    • +
    + + -
    -
      - <% @drivers.each do |driver| %> -
    • - <%= link_to "#{driver.name}", driver_path(driver.id) %> -
    • -
    • - <%= driver.average_rating %> -
    • - <% end %> -
        -
    + +
    +
      + <% @drivers.each do |driver| %> +
    • + <%= link_to "#{driver.name}", driver_path(driver.id) %> +
    • +
    • + <%= driver.average_rating %> +
    • + <% end %> +
        +
    + +
    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 55aa42f10..2b8f23486 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,5 +1,5 @@ - + RideshareRails <%= csrf_meta_tags %> @@ -12,12 +12,12 @@
    -
    diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index cf25b2123..28a85b346 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -1,7 +1,14 @@ -

    All Passengers

    - -<%= render partial: "shared/find_by_name", locals: {action_name: "Find Passenger", url: passenger_by_name_path} %> - +
    +
    +
    +

    + Passengers +

    +

    Find by Name

    + <%= render partial: "shared/find_by_name", locals: {action_name: "Find Passenger", url: passenger_by_name_path} %> +
    +
    +
    <% @passengers.each do |passenger| %>

    <%= link_to passenger.name, passenger_path(passenger) %>

    diff --git a/app/views/rideshare/index.html.erb b/app/views/rideshare/index.html.erb index 4bcd9886f..d8722f7ff 100644 --- a/app/views/rideshare/index.html.erb +++ b/app/views/rideshare/index.html.erb @@ -1,17 +1,14 @@ -
    +

    Welcome to our Rideshare App!

    +

    - This is a subtitle + <%= link_to 'For Drivers', drivers_path %> + <%= link_to 'For Passengers', passengers_path %>

    - -<%= link_to 'For Drivers', drivers_path %> -

    - -<%= link_to 'For Passengers', passengers_path %> diff --git a/app/views/shared/_display_trips.html.erb b/app/views/shared/_display_trips.html.erb index 05cb30e7b..840379e4c 100644 --- a/app/views/shared/_display_trips.html.erb +++ b/app/views/shared/_display_trips.html.erb @@ -15,7 +15,17 @@ <% else %>
  • <%= trip.passenger.name %>
  • <% end %> -
  • <%= trip.rating %>
  • +
  • + <% if trip.rating.nil? %> + <%= form_for trip do |f| %> + <%= f.label :rating %> + <%= f.number_field :rating %> + <%= f.submit 'Rate' %> + <% end %> + <% else %> + Rating: <%= trip.rating %> + <% end %> +
  • <%= trip.cost %>
<% end %> From 87465a200a2f529f96e036d248673a01fbaa5b2c Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 13:04:56 -0700 Subject: [PATCH 45/56] changes --- app/models/driver.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index c062fc446..1f558549e 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -15,7 +15,7 @@ def earnings def average_rating count = 0 stars = 0 - return 0 if trips.empty? + return 0 if trips.empty? || trips.length == 1 self.trips.each do |trip| next if trip.rating.nil? count +=1 @@ -34,13 +34,15 @@ def last_trip def self.the_driver drivers = Driver.where(disabled: false) - longest_driver_not_driving = Driver.first + longest_driver_not_driving = drivers.first drivers.each do |driver| unless driver.driver_on_trip if driver.trips.empty? || driver.last_trip.date == nil longest_driver_not_driving = driver - elsif longest_driver_not_driving == nil || longest_driver_not_driving.trips.empty? + return longest_driver_not_driving + elsif longest_driver_not_driving.trips.empty? longest_driver_not_driving = driver + return longest_driver_not_driving else if longest_driver_not_driving.last_trip.date > driver.last_trip.date longest_driver_not_driving = driver From 4034ffc5403d7feef642a66c77a666f86e76f76c Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 13:11:23 -0700 Subject: [PATCH 46/56] updated average rating, should have a working method, need to test --- app/models/driver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 264e6d41d..49e96af5c 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -15,7 +15,7 @@ def earnings def average_rating count = 0 stars = 0 - return 0 if trips.empty? || trips.length == 1 + return 0 if trips.empty? || (trips.length == 1 && trips.any? {|trip| trip.rating.nil? }) self.trips.each do |trip| next if trip.rating.nil? count +=1 From 13cbcd423f549ad29ffeb2bec410868f8a667be3 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 14:12:03 -0700 Subject: [PATCH 47/56] fixed average_rating method --- app/assets/stylesheets/application.css | 14 ++++++-- app/views/drivers/index.html.erb | 42 ++++++++++-------------- app/views/shared/_display_trips.html.erb | 4 ++- db/seeds.rb | 2 +- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 5a7a3ead4..394c82986 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -26,7 +26,7 @@ body { color: rgb(49, 213, 193); } -/*.display-trips { +.display-trips { display: flex; flex-wrap: nowrap; justify-content: space-around; @@ -37,9 +37,9 @@ body { .display-trips > li { text-align: center; min-width: 12vw; -}*/ +} -.show-page { +.show-page ul, .show-page.header { display: grid; grid-template-columns: 1fr 1fr; } @@ -47,3 +47,11 @@ body { .show-page li { text-align: center; } + +.show-page ul:nth-of-type(2n) { + background-color: rgba(96, 96, 102, 0.34); +} + +.show-page.header { + font-size: 1.5em; +} diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index bb633eaf1..dc2a374c0 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -10,29 +10,23 @@ +
+
    +
  • Name
  • +
  • Rating
  • +
- - - -
    -
  • Name
  • -
  • Rating
  • -
- - - -
-
    - <% @drivers.each do |driver| %> -
  • - <%= link_to "#{driver.name}", driver_path(driver.id) %> -
  • -
  • - <%= driver.average_rating %> -
  • - <% end %> -
      -
- -
+
+ <% @drivers.each do |driver| %> +
    +
  • + <%= link_to "#{driver.name}", driver_path(driver.id) %> +
  • +
  • + <%= driver.average_rating %> +
  • +
      + <% end %> +
+
diff --git a/app/views/shared/_display_trips.html.erb b/app/views/shared/_display_trips.html.erb index 840379e4c..c21e8ab12 100644 --- a/app/views/shared/_display_trips.html.erb +++ b/app/views/shared/_display_trips.html.erb @@ -16,12 +16,14 @@
  • <%= trip.passenger.name %>
  • <% end %>
  • - <% if trip.rating.nil? %> + <% if trip.rating.nil? && model == @passenger %> <%= form_for trip do |f| %> <%= f.label :rating %> <%= f.number_field :rating %> <%= f.submit 'Rate' %> <% end %> + <% elsif model == @driver && trip.rating.nil? %> + Rating: Ongoing trip <% else %> Rating: <%= trip.rating %> <% end %> diff --git a/db/seeds.rb b/db/seeds.rb index eab2a92ee..9fbce1080 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -57,7 +57,7 @@ trip.passenger_id = row['passenger_id'] trip.date = Date.strptime(row['date'], '%Y-%m-%d') trip.rating = row['rating'] - trip.cost = row['cost'] + trip.cost = (row['cost'] / 100.00) successful = trip.save if !successful trip_failures << trip From 7222325c0ef8f7d787f5e42fff8df0543368a1d4 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 14:31:25 -0700 Subject: [PATCH 48/56] passenger index page formats --- app/assets/stylesheets/application.css | 14 ++++++++++---- app/views/drivers/index.html.erb | 8 ++++++-- app/views/passengers/index.html.erb | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 394c82986..8740ea8c4 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -39,7 +39,10 @@ body { min-width: 12vw; } -.show-page ul, .show-page.header { +.show-page, .show-page.header { + border: thin solid rgba(184, 184, 184, 0.41); + margin: auto; + width: 70vw; display: grid; grid-template-columns: 1fr 1fr; } @@ -47,11 +50,14 @@ body { .show-page li { text-align: center; } - -.show-page ul:nth-of-type(2n) { - background-color: rgba(96, 96, 102, 0.34); +.show-page > ul li:nth-of-type(2n+1) { + background-color: rgba(184, 184, 184, 0.41); } .show-page.header { font-size: 1.5em; } + +.hero.is-primary { + margin-bottom: 5vh; +} diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index dc2a374c0..65a88d8cc 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -18,15 +18,19 @@
    - <% @drivers.each do |driver| %>
      + <% @drivers.each do |driver| %>
    • <%= link_to "#{driver.name}", driver_path(driver.id) %>
    • + <% end %> +
    +
      + <% @drivers.each do |driver| %>
    • <%= driver.average_rating %>
    • -
        <% end %> +
    diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 28a85b346..5360042e4 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -13,3 +13,28 @@ <% @passengers.each do |passenger| %>

    <%= link_to passenger.name, passenger_path(passenger) %>

    <% end %> + +
    +
      +
    • Name
    • +
    • Rating
    • +
    + + +
    +
      + <% @passengers.each do |passenger| %> +
    • + <%= link_to "#{passenger.name}", passenger_path(passenger.id) %> +
    • + <% end %> +
    +
      + <% @passengers.each do |passenger| %> +
    • + <%= passenger.average_rating %> +
    • + <% end %> +
        +
    +
    From 4a84393038266fed93c41f7ce49fc724498bf946 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 14:33:39 -0700 Subject: [PATCH 49/56] added a not found message when driver o passenger not found --- app/models/driver.rb | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 264e6d41d..66dee38e7 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -15,7 +15,7 @@ def earnings def average_rating count = 0 stars = 0 - return 0 if trips.empty? || trips.length == 1 + return 0 if trips.empty? || trips.length == 1 self.trips.each do |trip| next if trip.rating.nil? count +=1 @@ -24,34 +24,6 @@ def average_rating return stars/count end - def last_trips - ended_trips = self.trips.where.not(updated_at: nil) - return ended_trips.max_by {|trip| trip.updated_at } - end - - def check_if_no_trips - active_drivers = Driver.where(disabled: false) - drivers_with_no_trips = active_drivers.select {|driver| driver.trips.empty?} - - if !drivers_with_no_trips.empty? - return drivers_with_no_trips.first - end - - return active_drivers - end - - def get_last_driver - trips_or_driver = check_if_no_trips - - if trips_or_driver.length > 1 - last_trips = trips_or_driver.map {|driver| driver.last_trip} - last_trip = last_trips.order(:updated_at).first - - return last_trip - end - return trips_or_driver - end - def last_trip drivers_trips = self.trips.order(date: :desc) if drivers_trips.length == 0 From a8ddfde7e64fd7c384149222fffa207759c96e58 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 14:34:52 -0700 Subject: [PATCH 50/56] added not found to seach bar --- app/controllers/drivers_controller.rb | 10 +++----- app/controllers/passengers_controller.rb | 8 ++----- app/views/drivers/index.html.erb | 29 ++++++++++++++++-------- app/views/passengers/index.html.erb | 5 +++- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/controllers/drivers_controller.rb b/app/controllers/drivers_controller.rb index 885eefd4e..1068d0cdd 100644 --- a/app/controllers/drivers_controller.rb +++ b/app/controllers/drivers_controller.rb @@ -42,16 +42,12 @@ def update def by_name driver_name = params[:name] - @driver = Driver.where(disabled: false).find_by(name: driver_name) + @drivers = Driver.where(disabled: false).where(name: driver_name) - if @driver == nil - #flash.now[:error] = "Driver not found" - redirect_to drivers_path - else - redirect_to driver_path(@driver) - end + render :index end + def destroy driver = Driver.find(params[:id]) diff --git a/app/controllers/passengers_controller.rb b/app/controllers/passengers_controller.rb index 576d302f0..3d0bc47aa 100644 --- a/app/controllers/passengers_controller.rb +++ b/app/controllers/passengers_controller.rb @@ -50,13 +50,9 @@ def destroy def by_name passenger_name = params[:name] - @passenger = Passenger.where(disabled: false).find_by(name: passenger_name) + @passengers = Passenger.where(disabled: false).where(name: passenger_name) - if @passenger == nil - redirect_to passengers_path - else - redirect_to passenger_path(@passenger.id) - end + render :index end private diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index bb633eaf1..3be3bd9fc 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -24,15 +24,24 @@
      + <% if @drivers.length == 0 %> + <%="Driver not found"%> + <% else %> <% @drivers.each do |driver| %> -
    • - <%= link_to "#{driver.name}", driver_path(driver.id) %> -
    • -
    • - <%= driver.average_rating %> -
    • +
    • + <%= link_to "#{driver.name}", driver_path(driver.id) %> +
    • +
    • + <%if driver.driver_on_trip %> + <%= "On Trip" %> + <%end%> +
    • +
    • + <%= driver.average_rating %> +
    • <% end %> -
        -
    - - + <%end%> +
      + + + diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 28a85b346..2289cc6a0 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -9,7 +9,10 @@ - +<% if @passengers.length == 0 %> +<%="Passenger not found"%> +<% else %> <% @passengers.each do |passenger| %>

      <%= link_to passenger.name, passenger_path(passenger) %>

      <% end %> +<% end %> From bece5dd3b7fc9314271b5a5e8e25d5bb12befbb6 Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 15:04:02 -0700 Subject: [PATCH 51/56] added driver and passenger not found for search --- app/models/driver.rb | 6 ++--- app/models/passenger.rb | 2 ++ app/views/drivers/index.html.erb | 4 ---- app/views/passengers/index.html.erb | 34 ++++++++++------------------- 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/app/models/driver.rb b/app/models/driver.rb index 729dd39f1..28440f03f 100644 --- a/app/models/driver.rb +++ b/app/models/driver.rb @@ -15,11 +15,9 @@ def earnings def average_rating count = 0 stars = 0 -<<<<<<< HEAD - return 0 if trips.empty? || trips.length == 1 -======= + return 0 if trips.empty? || (trips.length == 1 && trips.any? {|trip| trip.rating.nil? }) ->>>>>>> 7222325c0ef8f7d787f5e42fff8df0543368a1d4 + self.trips.each do |trip| next if trip.rating.nil? count +=1 diff --git a/app/models/passenger.rb b/app/models/passenger.rb index c0e082d86..e6143f2fb 100644 --- a/app/models/passenger.rb +++ b/app/models/passenger.rb @@ -10,4 +10,6 @@ def total_spent end return total.round(2) end + + end diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 52db07067..5a9a77336 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -16,9 +16,6 @@
    • Rating
    - -<<<<<<< HEAD -=======
      <% if @drivers.length == 0 %> @@ -40,4 +37,3 @@
    ->>>>>>> 7222325c0ef8f7d787f5e42fff8df0543368a1d4 diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 299ca2067..2545ef999 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -9,38 +9,28 @@ -<% if @passengers.length == 0 %> -<%="Passenger not found"%> -<% else %> -<% @passengers.each do |passenger| %> -

    <%= link_to passenger.name, passenger_path(passenger) %>

    -<% end %> -<<<<<<< HEAD -<% end %> -======= +
    • Name
    • -
    • Rating
      - <% @passengers.each do |passenger| %> -
    • - <%= link_to "#{passenger.name}", passenger_path(passenger.id) %> -
    • + <% if @passengers.length == 0 %> + <%="Passenger not found"%> + <% else %> + <% @passengers.each do |passenger| %> +
    • + <%= link_to "#{passenger.name}", passenger_path(passenger.id) %> +
    • + <% end %> <% end %>
    -
      - <% @passengers.each do |passenger| %> -
    • - <%= passenger.average_rating %> -
    • - <% end %> -
        + + +
    ->>>>>>> 7222325c0ef8f7d787f5e42fff8df0543368a1d4 From a21f00d11b8ca45ba032f69464861a9827b74fad Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 15:17:59 -0700 Subject: [PATCH 52/56] fixed passenger page styling --- app/assets/stylesheets/application.css | 20 ++++++++++++++++++-- app/views/drivers/index.html.erb | 5 +++++ app/views/passengers/index.html.erb | 4 ++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 8740ea8c4..8facaed31 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -50,14 +50,30 @@ body { .show-page li { text-align: center; } -.show-page > ul li:nth-of-type(2n+1) { +.show-page > ul li:nth-of-type(2n+1), .passenger-page > ul li:nth-of-type(2n+1) { background-color: rgba(184, 184, 184, 0.41); } -.show-page.header { +.show-page.header, .passenger-page.header { font-size: 1.5em; } + +.passenger-page { + border: thin solid rgba(184, 184, 184, 0.41); + margin: auto; + width: 70vw; + text-align: center; +} + .hero.is-primary { margin-bottom: 5vh; } + +.on-trip { + border: thin solid #ffdd57; + border-radius: 4px; + padding: 2px; + background-color: #ffdd57; + color: black; +} diff --git a/app/views/drivers/index.html.erb b/app/views/drivers/index.html.erb index 5a9a77336..1d5e0d328 100644 --- a/app/views/drivers/index.html.erb +++ b/app/views/drivers/index.html.erb @@ -24,6 +24,11 @@ <% @drivers.each do |driver| %>
  • <%= link_to "#{driver.name}", driver_path(driver.id) %> + <% if driver.driver_on_trip %> + + On Trip + + <% end %>
  • <% end %> diff --git a/app/views/passengers/index.html.erb b/app/views/passengers/index.html.erb index 2545ef999..5917bf30e 100644 --- a/app/views/passengers/index.html.erb +++ b/app/views/passengers/index.html.erb @@ -12,12 +12,12 @@
    -
      +
      • Name
      -
      +
        <% if @passengers.length == 0 %> <%="Passenger not found"%> From 60f031434c0171a434494a45530cf199f20ca7fc Mon Sep 17 00:00:00 2001 From: Winifred Irarrazaval Date: Fri, 6 Apr 2018 15:29:42 -0700 Subject: [PATCH 53/56] fixed a bug --- db/seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index 9fbce1080..b0ba1e78b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -57,7 +57,7 @@ trip.passenger_id = row['passenger_id'] trip.date = Date.strptime(row['date'], '%Y-%m-%d') trip.rating = row['rating'] - trip.cost = (row['cost'] / 100.00) + trip.cost = (row['cost'].to_i / 100.00) successful = trip.save if !successful trip_failures << trip From 21f4719782a63ceb297295406787b672f5efcb99 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 16:50:49 -0700 Subject: [PATCH 54/56] added a partial for passenger and driver new and edit views --- app/assets/stylesheets/application.css | 10 ++++++ app/views/drivers/_form.html.erb | 19 ----------- app/views/drivers/edit.html.erb | 2 +- app/views/drivers/new.html.erb | 2 +- app/views/drivers/show.html.erb | 23 ++++++++----- app/views/passengers/_form.html.erb | 18 ---------- app/views/passengers/edit.html.erb | 2 +- app/views/passengers/new.html.erb | 2 +- app/views/passengers/show.html.erb | 25 +++++++++----- .../shared/_new_driver_passenger.html.erb | 34 +++++++++++++++++++ app/views/trips/show.html.erb | 11 ++++-- 11 files changed, 88 insertions(+), 60 deletions(-) delete mode 100644 app/views/drivers/_form.html.erb delete mode 100644 app/views/passengers/_form.html.erb create mode 100644 app/views/shared/_new_driver_passenger.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 8facaed31..42936416f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -77,3 +77,13 @@ body { background-color: #ffdd57; color: black; } + +.find-by-name { + width: 70vw; + margin: auto; +} + +.errors { + list-style-type: none; + margin-left: 15vw; +} diff --git a/app/views/drivers/_form.html.erb b/app/views/drivers/_form.html.erb deleted file mode 100644 index 96fdb82a8..000000000 --- a/app/views/drivers/_form.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -

        - <%= page_title %> -

        - -<% if @driver.errors.any?%> - <% @driver.errors.each do |column, message|%> - <%= column %> - <%= message %> - <%end%> -<%end%> - - -<%= form_for @driver do |f| %> - <%= f.label :name %> - <%= f.text_field :name %> - - <%= f.label :vin %> - <%= f.text_field :vin %> - <%= f.submit action_name %> -<% end %> diff --git a/app/views/drivers/edit.html.erb b/app/views/drivers/edit.html.erb index 5d4f1ecab..644f1055c 100644 --- a/app/views/drivers/edit.html.erb +++ b/app/views/drivers/edit.html.erb @@ -1 +1 @@ -<%= render partial: "form" , locals: {action_name: 'Edit Driver', page_title: "Update Driver"}%> +<%= render partial: "shared/new_driver_passenger" , locals: {action_name: 'Edit Driver', page_title: "Update Driver", model: @driver} %> diff --git a/app/views/drivers/new.html.erb b/app/views/drivers/new.html.erb index 48ec3995f..69b71dd53 100644 --- a/app/views/drivers/new.html.erb +++ b/app/views/drivers/new.html.erb @@ -1 +1 @@ -<%= render partial: "form" , locals: {action_name: 'Add Driver', page_title: "Create New Driver"}%> +<%= render partial: "shared/new_driver_passenger" , locals: {action_name: 'Create Driver', page_title: "Create New Driver", model: @driver} %> diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index 851ca69c6..c90407053 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -1,13 +1,20 @@ -

        Driver info:

        +
        +
        +
        +

        + <%=@driver.name%> +

        +

        <%= link_to("Edit info", edit_driver_path(@driver.id)) %>

        +

        ID : <%=@driver.id%>

        +

        VIN : <%=@driver.vin%>

        +

        Total made in trips: $<%= @driver.earnings %>

        +

        Average rating: <%= @driver.average_rating%>

        +
        +
        +
        + -

        <%=@driver.name%>

        -

        <%= link_to("Edit info", edit_driver_path(@driver.id)) %>

        -

        ID : <%=@driver.id%>

        -

        VIN : <%=@driver.vin%>

        -

        Total made in trips: $<%= @driver.earnings %>

        -

        Average rating: <%= @driver.average_rating%>

        -

        <%= render partial: 'shared/display_trips', locals: {model: @driver, pass_driver: 'Passenger'} %>

        diff --git a/app/views/passengers/_form.html.erb b/app/views/passengers/_form.html.erb deleted file mode 100644 index 709dabaee..000000000 --- a/app/views/passengers/_form.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -

        - <%= page_title %> -

        - -<% if @passenger.errors.any?%> -<% @passenger.errors.each do |column, message|%> -<%= column%> - <%= message %> -<%end%> -<%end%> - -<%= form_for @passenger do |f| %> -<%= f.label :name %> -<%= f.text_field :name %> - -<%= f.label :phone_num %> -<%= f.text_field :phone_num %> -<%= f.submit action_name %> -<% end %> diff --git a/app/views/passengers/edit.html.erb b/app/views/passengers/edit.html.erb index 3ef630e59..97fa5e63b 100644 --- a/app/views/passengers/edit.html.erb +++ b/app/views/passengers/edit.html.erb @@ -1 +1 @@ -<%= render partial: "form" , locals: {action_name: 'Edit Passenger', page_title: "Create New Passenger"} %> +<%= render partial: "shared/new_driver_passenger" , locals: {action_name: 'Edit Passenger', page_title: "Edit Passenger", model: @passenger} %> diff --git a/app/views/passengers/new.html.erb b/app/views/passengers/new.html.erb index 1b271162e..81bf822f4 100644 --- a/app/views/passengers/new.html.erb +++ b/app/views/passengers/new.html.erb @@ -1 +1 @@ -<%= render partial: "form" , locals: {action_name: 'Create Passenger', page_title: "Create New Passenger"} %> +<%= render partial: "shared/new_driver_passenger" , locals: {action_name: 'Create Passenger', page_title: "Create New Passenger", model: @passenger} %> diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 4d56ea30d..1fb16e800 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -1,14 +1,21 @@ -

        Passenger info:

        +
        +
        +
        +

        + <%=@passenger.name%> +

        +

        <%= link_to("Edit info", edit_passenger_path(@passenger.id)) %>

        +

        ID : <%= @passenger.id %>

        +

        Phone #: <%= @passenger.phone_num %>

        +

        Total Spent: $<%= @passenger.total_spent %>

        +
        +
        +
        -

        <%= @passenger.name %>

        -

        <%= link_to("Edit info", edit_passenger_path(@passenger.id)) %>

        -

        ID : <%= @passenger.id %>

        -

        Phone #: <%= @passenger.phone_num %>

        -

        Total Spent: $<%= @passenger.total_spent %>

        -
        -

        <%= link_to 'Request Trip', passenger_trips_path(@passenger), method: :post %> -
        + +

        <%= link_to 'Request Trip', passenger_trips_path(@passenger), method: :post, class: 'button is-large is-link' %> + <%= render partial: 'shared/display_trips', locals: {model: @passenger, pass_driver: 'Driver'} %> diff --git a/app/views/shared/_new_driver_passenger.html.erb b/app/views/shared/_new_driver_passenger.html.erb new file mode 100644 index 000000000..dbd46ae17 --- /dev/null +++ b/app/views/shared/_new_driver_passenger.html.erb @@ -0,0 +1,34 @@ +

        +
        +
        +

        + <%= page_title %> +

        +
        +
        +
        + +<% if model.errors.any?%> + <% model.errors.each do |column, message|%> +
      • + <%= column.capitalize %> - <%= message %> +
      • + <%end%> +<%end%> + +
        + <%= form_for model do |f| %> + <%= f.label :name, class: 'label' %> + <%= f.text_field :name, class: 'control input' %> + + <% if model = @passenger %> + <%= f.label :phone_num, class: 'label' %> + <%= f.text_field :phone_num, class: 'control input' %> + <%= f.submit action_name, class: 'control button is-link' %> + <% elsif model = @driver %> + <%= f.label :vin, class: 'label' %> + <%= f.text_field :vin, class: 'control input' %> + <%= f.submit action_name, class: 'control button is-link' %> + <% end %> + <% end %> +
        diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index a77231ceb..c24916c2d 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -1,5 +1,12 @@ - -

        Trip <%= @trip.id%> Details:

        +
        +
        +
        +

        + Trip <%= @trip.id %> +

        +
        +
        +

        Date : <%= @trip.date%>

        Cost: $<%= @trip.cost%>

        From d72d3fb0b5afe6858c99688f499d6470f8b8cd58 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 17:23:15 -0700 Subject: [PATCH 55/56] updated error showing when rating a trip other than 1..5 --- app/controllers/trips_controller.rb | 22 ++++++++++++++-------- app/models/trip.rb | 2 +- app/views/trips/index.html.erb | 3 --- app/views/trips/show.html.erb | 16 +++++++++++++--- config/routes.rb | 8 +++----- 5 files changed, 31 insertions(+), 20 deletions(-) delete mode 100644 app/views/trips/index.html.erb diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 5030b9f76..fc9d3d398 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -12,9 +12,15 @@ def index end def show - @trip = Trip.find(params[:id]) - @driver = Driver.find(@trip.driver_id) - @passenger = Passenger.find(@trip.passenger_id) + if params[:trip] + @trip = Trip.find(params[:trip][:id]) + @driver = @trip.driver + @passenger = @trip.passenger + else + @trip = Trip.find(params[:id]) + @driver = Driver.find(@trip.driver_id) + @passenger = Passenger.find(@trip.passenger_id) + end end def new @@ -44,11 +50,11 @@ def update @trip = Trip.find(params[:id]) @trip.rating = params[:trip][:rating] - @trip.save - redirect_to trip_path(@trip) - end - - def destroy + if @trip.save + redirect_to trip_path(@trip) + else + render :show + end end private diff --git a/app/models/trip.rb b/app/models/trip.rb index f29ba163a..0defe63cf 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,6 +1,6 @@ class Trip < ApplicationRecord belongs_to :driver belongs_to :passenger - validates :rating, on: :update ,numericality: {greater_than_or_equal_to: 1, less_than_or_equal_to: 5 } + validates :rating, on: :update, numericality: {greater_than_or_equal_to: 1, less_than_or_equal_to: 5 } end diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb deleted file mode 100644 index e0271f350..000000000 --- a/app/views/trips/index.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% @trips.each do |trip| %> -

        <%= link_to trip.id, trip_path(trip)%>

        -<% end %> diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index c24916c2d..5af8cbeb6 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -8,18 +8,28 @@
      +<% if @trip.errors.any?%> + <% @trip.errors.each do |column, message|%> +
    • + <%= column.capitalize %> - <%= message %> +
    • + <%end%> +<%end%> +

      Date : <%= @trip.date%>

      Cost: $<%= @trip.cost%>

      - <% if @trip.rating.nil? %> + <% if @trip.rating.nil? || @trip.errors.any? %> <%= form_for @trip do |f| %> <%= f.label :rating %> <%= f.number_field :rating %> + <%= f.hidden_field :driver_id, value: @trip.driver_id %> + <%= f.hidden_field :passenger_id, value: @trip.passenger_id %> <%= f.submit 'Rate' %> <% end %> <% else %> Rating: <%= @trip.rating %> <% end %>

      -

      Driver: <%= @driver.name %>

      -

      Passenger: <%= @passenger.name %>

      +

      Driver: <%= @trip.driver.name %>

      +

      Passenger: <%= @trip.passenger.name %>

      diff --git a/config/routes.rb b/config/routes.rb index 3ee5e6206..d73d976d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,15 +3,13 @@ root 'rideshare#index' get 'drivers/by_name', to: 'drivers#by_name', as: 'by_name' -resources :drivers do - resources :trips, only: [:index] -end +resources :drivers get 'passengers/by_name', to: 'passengers#by_name', as: 'passenger_by_name' resources :passengers do - resources :trips, only: [:index, :new, :create] + resources :trips, only: [:new, :create] end -resources :trips +resources :trips, except: [:destroy] resources :rideshare, only: [:index] end From e9adbe572691ff70ddd23e6b2a4d898d48086521 Mon Sep 17 00:00:00 2001 From: Tor Shimizu Date: Fri, 6 Apr 2018 17:28:34 -0700 Subject: [PATCH 56/56] changed edit info to look like a button --- app/views/drivers/show.html.erb | 3 ++- app/views/passengers/show.html.erb | 3 ++- app/views/shared/_display_trips.html.erb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/drivers/show.html.erb b/app/views/drivers/show.html.erb index c90407053..fa772aed5 100644 --- a/app/views/drivers/show.html.erb +++ b/app/views/drivers/show.html.erb @@ -4,7 +4,8 @@

      <%=@driver.name%>

      -

      <%= link_to("Edit info", edit_driver_path(@driver.id)) %>

      +

      <%= link_to("Edit info", edit_driver_path(@driver.id), class: 'button is-small is-info')%>

      +

      ID : <%=@driver.id%>

      VIN : <%=@driver.vin%>

      Total made in trips: $<%= @driver.earnings %>

      diff --git a/app/views/passengers/show.html.erb b/app/views/passengers/show.html.erb index 1fb16e800..1a69ac416 100644 --- a/app/views/passengers/show.html.erb +++ b/app/views/passengers/show.html.erb @@ -4,7 +4,8 @@

      <%=@passenger.name%>

      -

      <%= link_to("Edit info", edit_passenger_path(@passenger.id)) %>

      +

      <%= link_to("Edit info", edit_passenger_path(@passenger.id), class: 'button is-small is-info') %>

      +

      ID : <%= @passenger.id %>

      Phone #: <%= @passenger.phone_num %>

      Total Spent: $<%= @passenger.total_spent %>

      diff --git a/app/views/shared/_display_trips.html.erb b/app/views/shared/_display_trips.html.erb index c21e8ab12..1d8b816ef 100644 --- a/app/views/shared/_display_trips.html.erb +++ b/app/views/shared/_display_trips.html.erb @@ -23,9 +23,9 @@ <%= f.submit 'Rate' %> <% end %> <% elsif model == @driver && trip.rating.nil? %> - Rating: Ongoing trip + Ongoing trip <% else %> - Rating: <%= trip.rating %> + <%= trip.rating %> <% end %>
    • <%= trip.cost %>