-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Div-Hannah Rideshare #11
base: master
Are you sure you want to change the base?
Conversation
Rideshare RailsWhat We're Looking For
|
|
||
def destroy | ||
driver = Driver.find_by(id: params[:id].to_i) | ||
driver.destroy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work if the driver has any trips!
|
||
def destroy | ||
passenger = Passenger.find_by(id: params[:id].to_i) | ||
passenger.destroy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work if the passenger has any trips.
return (total.to_f / self.trips.length).round(2) | ||
end | ||
|
||
def self.search(term, page) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search! Neat!
However it doesn't look like you have it hooked into the webpage
|
||
resources :passengers | ||
|
||
resources :passengers do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need resources :passengers
in here twice.
resources :passengers | ||
|
||
resources :passengers do | ||
resources :trips, only: [:index, :new, :create] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need an :index
action for trips in this context?
validates :passenger_id, presence: true | ||
validates :driver_id, presence: true | ||
validates :date, presence: true | ||
validates :cost, presence: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also require that cost be numeric and positive.
validates :driver_id, presence: true | ||
validates :date, presence: true | ||
validates :cost, presence: true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rating should also have a validation. It should be 1-5.
belongs_to :driver | ||
belongs_to :passenger | ||
#can you write these all in one line instead of individually? | ||
validates :passenger_id, presence: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the trip belongs to driver, this validation is unnecessary.
return trips_total | ||
end | ||
|
||
def self.search(term, page) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search! Neat! It doesn't look like it's integrated into the view/controller.
</div> | ||
</div> | ||
<article class="home-button"> | ||
<%= link_to image_tag("https://www.iconsdb.com/icons/preview/white/home-xxl.png", alt: "home buttom"), root_path %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems broken when I ran it.
Thanks for the feedback Chris!
…On Sun, Oct 7, 2018, 6:24 PM Chris M ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In app/controllers/drivers_controller.rb
<#11 (comment)>
:
> + @driver = Driver.find_by(id: params[:id].to_i)
+ end
+ end
+
+ def update
+ @driver = Driver.find_by(id: params[:id].to_i)
+ if @driver.update(driver_params)
+ redirect_to driver_path
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ driver = Driver.find_by(id: params[:id].to_i)
+ driver.destroy
This won't work if the driver has any trips!
------------------------------
In app/controllers/passengers_controller.rb
<#11 (comment)>
:
> + @Passenger = Passenger.find_by(id: params[:id].to_i)
+ end
+
+ def update
+ @Passenger = Passenger.find_by(id: params[:id].to_i)
+ if @passenger.update(passenger_params)
+ redirect_to ***@***.***)
+ else
+ render :edit
+ end
+ end
+
+
+ def destroy
+ passenger = Passenger.find_by(id: params[:id].to_i)
+ passenger.destroy
This won't work if the passenger has any trips.
------------------------------
In app/models/driver.rb
<#11 (comment)>
:
> + self.trips.each do |trip|
+ trip_price = (trip.cost - 1.65) * 0.80
+ total += trip_price
+ end
+ return total
+ end
+
+ def average_rating
+ total = 0
+ self.trips.each do |trip|
+ total += trip.rating
+ end
+ return (total.to_f / self.trips.length).round(2)
+ end
+
+ def self.search(term, page)
Search! Neat!
However it doesn't look like you have it hooked into the webpage
------------------------------
In config/routes.rb
<#11 (comment)>
:
> @@ -0,0 +1,18 @@
+Rails.application.routes.draw do
+ root 'welcome#index'
+
+ get 'welcome/index'
+ # why are the paths different between resource trips and the trips I wrote?
+ resources :trips
+
+ resources :drivers
+
+ resources :passengers
+
+ resources :passengers do
You don't need resources :passengers in here twice.
------------------------------
In config/routes.rb
<#11 (comment)>
:
> @@ -0,0 +1,18 @@
+Rails.application.routes.draw do
+ root 'welcome#index'
+
+ get 'welcome/index'
+ # why are the paths different between resource trips and the trips I wrote?
+ resources :trips
+
+ resources :drivers
+
+ resources :passengers
+
+ resources :passengers do
+ resources :trips, only: [:index, :new, :create]
Do you need an :index action for trips in this context?
------------------------------
In app/views/trips/_form.html.erb
<#11 (comment)>
:
> +<div class="passenger-form">
+ <section class="form-contents form-section">
+<% if @trip.errors.any? %>
+ <ul class="errors">
+ <% @trip.errors.each do |column, message| %>
+ <li>
+ <strong><%= column.capitalize %></strong> <%= message %>
+ </li>
+ <% end %>
+ </ul>
+<% end %>
+
+ <h1><%= page_title %></h1>
+ <%= form_with model: @trip do |f| %>
+ <p>
+ <%= f.label :passenger_id %>
Should the passenger be able to edit their ID number?
I would make this a hidden field,
I would also do something similar for driver.
Also you don't *have* to create the trip via a form. You could have a
link which directly calls create, and the trip is created with the given
passenger, and assigns a driver, todays date and a random price.
------------------------------
In app/models/trip.rb
<#11 (comment)>
:
> @@ -0,0 +1,11 @@
+class Trip < ApplicationRecord
+ belongs_to :driver
+ belongs_to :passenger
+ #can you write these all in one line instead of individually?
+ validates :passenger_id, presence: true
+ validates :driver_id, presence: true
+ validates :date, presence: true
+ validates :cost, presence: true
You should also require that cost be numeric and positive.
------------------------------
In app/models/trip.rb
<#11 (comment)>
:
> @@ -0,0 +1,11 @@
+class Trip < ApplicationRecord
+ belongs_to :driver
+ belongs_to :passenger
+ #can you write these all in one line instead of individually?
+ validates :passenger_id, presence: true
+ validates :driver_id, presence: true
+ validates :date, presence: true
+ validates :cost, presence: true
+
Rating should also have a validation. It should be 1-5.
------------------------------
In app/models/trip.rb
<#11 (comment)>
:
> @@ -0,0 +1,11 @@
+class Trip < ApplicationRecord
+ belongs_to :driver
+ belongs_to :passenger
+ #can you write these all in one line instead of individually?
+ validates :passenger_id, presence: true
If the trip belongs to driver, this validation is unnecessary.
------------------------------
In app/models/passenger.rb
<#11 (comment)>
:
> +class Passenger < ApplicationRecord
+ has_many :trips
+
+ validates :name, presence: true
+ validates :phone_num, presence: true
+
+ def total_charges
+ trips = self.trips
+ trips_total = 0
+ trips.each do |trip|
+ trips_total += trip.cost
+ end
+ return trips_total
+ end
+
+ def self.search(term, page)
Search! Neat! It doesn't look like it's integrated into the
view/controller.
------------------------------
In app/views/layouts/application.html.erb
<#11 (comment)>
:
> + <div class="driver-dropdown dropdown">
+ <button class="dropbtn">Driver</button>
+ <div class="dropdown-content">
+ <p><%= link_to "All Drivers", drivers_path %></p>
+ <p><%= link_to "Add a New Driver", new_driver_path %></p>
+ </div>
+ </div>
+ <div class="dropdown">
+ <button class="dropbtn">Passenger</button>
+ <div class="dropdown-content">
+ <p><%= link_to "All Passengers", passengers_path %></p>
+ <p><%= link_to "Add a New Passenger", new_passenger_path %></p>
+ </div>
+ </div>
+ <article class="home-button">
+ <%= link_to image_tag("https://www.iconsdb.com/icons/preview/white/home-xxl.png", alt: "home buttom"), root_path %>
Seems broken when I ran it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AgAOSeE6qKCnCA6u-tlz6Gqt1gjOkFYjks5uiqk7gaJpZM4XLBzi>
.
|
Rideshare-Rails
Congratulations! You're submitting your assignment! These comprehension questions should be answered by both partners together, not by a single teammate.
Comprehension Questions