mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Refactor: Apply Rails best practice for early returns
Follow Rails convention of using "render/redirect ... and return" instead of standalone return statements in controller actions. ## Changes **Shared::TripsController#show** Before: ```ruby unless @trip&.public_accessible? return redirect_to root_path, alert: '...' end ``` After: ```ruby redirect_to root_path, alert: '...' and return unless @trip&.public_accessible? ``` **TripsController#update** Before: ```ruby if params[:sharing] return update_sharing end ``` After: ```ruby update_sharing and return if params[:sharing] ``` ## Benefits - More idiomatic Rails code - Clearer intent with single-line guard clauses - Prevents potential double render issues - Follows community best practices
This commit is contained in:
parent
9fba3ce4ca
commit
429f90e666
2 changed files with 2 additions and 7 deletions
|
|
@ -4,10 +4,7 @@ class Shared::TripsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@trip = Trip.find_by(sharing_uuid: params[:trip_uuid])
|
@trip = Trip.find_by(sharing_uuid: params[:trip_uuid])
|
||||||
|
|
||||||
unless @trip&.public_accessible?
|
redirect_to root_path, alert: 'Shared trip not found or no longer available' and return unless @trip&.public_accessible?
|
||||||
return redirect_to root_path,
|
|
||||||
alert: 'Shared trip not found or no longer available'
|
|
||||||
end
|
|
||||||
|
|
||||||
@user = @trip.user
|
@user = @trip.user
|
||||||
@is_public_view = true
|
@is_public_view = true
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,7 @@ class TripsController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
# Handle sharing settings update (JSON response)
|
# Handle sharing settings update (JSON response)
|
||||||
if params[:sharing]
|
update_sharing and return if params[:sharing]
|
||||||
return update_sharing
|
|
||||||
end
|
|
||||||
|
|
||||||
# Handle regular trip update
|
# Handle regular trip update
|
||||||
if @trip.update(trip_params)
|
if @trip.update(trip_params)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue