From 429f90e6663c409aeca99b9fce8e36d59afbdf6a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Nov 2025 11:49:05 +0000 Subject: [PATCH] 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 --- app/controllers/shared/trips_controller.rb | 5 +---- app/controllers/trips_controller.rb | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/controllers/shared/trips_controller.rb b/app/controllers/shared/trips_controller.rb index 570e6073..9b583295 100644 --- a/app/controllers/shared/trips_controller.rb +++ b/app/controllers/shared/trips_controller.rb @@ -4,10 +4,7 @@ class Shared::TripsController < ApplicationController def show @trip = Trip.find_by(sharing_uuid: params[:trip_uuid]) - unless @trip&.public_accessible? - return redirect_to root_path, - alert: 'Shared trip not found or no longer available' - end + redirect_to root_path, alert: 'Shared trip not found or no longer available' and return unless @trip&.public_accessible? @user = @trip.user @is_public_view = true diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 3b8ec498..2818b4af 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -40,9 +40,7 @@ class TripsController < ApplicationController def update # Handle sharing settings update (JSON response) - if params[:sharing] - return update_sharing - end + update_sharing and return if params[:sharing] # Handle regular trip update if @trip.update(trip_params)