-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add Vagons #2
base: master
Are you sure you want to change the base?
Add Vagons #2
Conversation
private | ||
|
||
def set_number | ||
self.number = Random.rand(0...10) |
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.
Если у тебя все номера будут от 0 до 10, то номера могут повторяться, а этого по условиям задачи быть не должно. Надо делать по другому: брать максимальное значение номера вагона у поезда и прибавлять к нему 1. В этом поможет метод maximum
Исправь замечания и я не увидел возможности указания времени прибытия и отправления на станцию |
private | ||
|
||
def set_number | ||
self.number = Vagon.maximum('number') + 1 |
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.
Опять же ты берешь максимальное значение номера вагона глобально. А надо в рамках поезда, т.е. у 2-х разных поездов могут быть вагоны с одинаковыми номерами. А у тебя получается, что если у одного поезда есть вагон с номером 1, то у другого, нумерация будет уже с 2.
С 15-м в целом ок, но исправь замечания |
|
||
scope :count_order, -> { order(:count) } | ||
|
||
def self.show_trains |
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.
В чем смысл этого метода? Он перебирает названия у станций, но возвращает массив маршрутов, т.к. each возвращает оригинальный массив. И в чем тогда смысл?
Исправь замечания |
route1 = RailwayStation.find(start_station).routes.all | ||
route1.each do |route1| | ||
route1.trains.to_a.each do |train| | ||
return train.title |
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.
Здесь у тебя будет возвращено название только первого поезда, т.к. после return происходит выход из всего метода.
route1 = RailwayStation.find(start_station).routes.all | ||
route2 = RailwayStation.find(end_station).routes.all | ||
routes = route1 & route2 | ||
routes.each do |myroutes| |
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.
Я же тебе написал как найти все поезда одним запросом без перебора: Train.where(route: routes).all
@@ -0,0 +1,28 @@ | |||
<%= form_for(@ticket) do |f| %> |
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.
А как мы передаем от куда и до куда у нас билет?
С поиском худо-бедно разобрались (хотя я написал как надо сделать), но это еще далеко не конец. Исправь остальные замечания. |
@@ -9,13 +9,16 @@ def show | |||
|
|||
def new | |||
@ticket = Ticket.new | |||
@ticket.first_station = Ticket.result_start(params[:first_station]) |
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.
Зачем тебе методы result_start и result_end, когда в параметрах приходят id станции и ее можно загрузить по RailwayStation.find?
Ладно, будем считать, что сделано. Принимаю. |
def edit | ||
end | ||
|
||
def 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.
В задании не сказано, что админ может создавать билеты
Исправь добавление имени при регситрации |
@@ -2,4 +2,25 @@ class ApplicationController < ActionController::Base | |||
# Prevent CSRF attacks by raising an exception. | |||
# For APIs, you may want to use :null_session instead. | |||
protect_from_forgery with: :exception | |||
before_action :configure_sign_up_params, if: :devise_controller? | |||
before_action :configure_sign_in_params, if: :devise_controller? |
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.
Зачем одно и то же дважды?
Ок, принимаю, без усложненного. |
No description provided.