Severin & Kimberley - Carets#15
Conversation
|
Hey all! The following things didn't work for me on my machine:
Your site looks beautiful! |
| driver = Driver.find_by(id: params[:id]) | ||
|
|
||
| if driver.destroy | ||
| redirect_to driver_path |
There was a problem hiding this comment.
should redirect to drivers_path, otherwise it tries to access an individual driver's show page with the id in the params
| end | ||
|
|
||
| def self.assign_driver | ||
| (Driver.find_by(status: true)).id |
There was a problem hiding this comment.
there needs to be handling for if Driver.find_by returns nil
| @@ -0,0 +1,4 @@ | |||
| class Trip < ApplicationRecord | |||
| belongs_to :driver | |||
| belongs_to :passenger | |||
There was a problem hiding this comment.
There are no validations on Trip creation. Either add some validations here, or handle in your controller what happens if there's no date or cost passed into the form
| def total_earnings | ||
| sum = 0 | ||
| trips.each do |trip| | ||
| sum += trip.cost |
There was a problem hiding this comment.
Without validations on the Trip model, a trip with a nil cost can be associated with a driver. Then, this driver iterates through all of its trips. When it executes trip.cost, it returns nil, and then tries to add it to sum, which produces an error
Rideshare-RailsWhat We're Looking For
|
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