Last active
May 30, 2016 09:40
-
-
Save aya-soft/5c62ef8f26c7a911507f99748971fc09 to your computer and use it in GitHub Desktop.
Unless не используют с else, т.к. он и так трудно понятный, а тут станет вообще ненужным, потому что его можно легко превратить в легко понимаемый if-else
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def new | |
unless current_user.service_station.present? | |
redirect_to new_profile_service_station_path | |
else | |
service = current_user.service_station.service_station_comments.where("spare_id = ?", params[:spare_id]) | |
if service.present? | |
redirect_to "/profile/service_station_comments/#{service.first.id}/edit" | |
end | |
@comment = ServiceStationComment.new | |
gon.labor_times_price = current_user.service_station.labor_times_price | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Когда выполняется and return продолжается выполнение кода в текущем контроллере, что нам не нужно, т.к. у нас переменная comment будет nil, потому что не может быть комментариев у несуществующего автосервиса. Финал привожу
def new
if current_user.service_station
@existing_comment = current_user.service_station.service_station_comments.find_by_spare_id(params[:spare_id])
redirect_to edit_profile_service_station_comment_path(@existing_comment) if @existing_comment
@comment = ServiceStationComment.new
@labor_times_price = current_user.service_station.labor_times_price
else
redirect_to new_profile_service_station_path, notice: "Сначала добавьте автосервис!"
end
end