From 736aa15a1e3d3edfa7598e19a4d264a03fbd80fa Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Nov 2025 12:55:02 +0000 Subject: [PATCH] Refactor: Simplify boolean conversion with helper method - Extract to_boolean helper method for cleaner code - Avoid repeating ActiveModel::Type::Boolean.new.cast() - Consistent approach throughout the controller - More readable: to_boolean(value) vs verbose casting --- app/controllers/trips_controller.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 8c3c711a..d4921f01 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -74,11 +74,11 @@ class TripsController < ApplicationController def handle_sharing_update sharing_params = params[:trip][:sharing] - if ActiveModel::Type::Boolean.new.cast(sharing_params[:enabled]) + if to_boolean(sharing_params[:enabled]) sharing_options = { expiration: sharing_params[:expiration] || '24h', - share_notes: ActiveModel::Type::Boolean.new.cast(sharing_params[:share_notes]), - share_photos: ActiveModel::Type::Boolean.new.cast(sharing_params[:share_photos]) + share_notes: to_boolean(sharing_params[:share_notes]), + share_photos: to_boolean(sharing_params[:share_photos]) } @trip.enable_sharing!(**sharing_options) @@ -90,4 +90,8 @@ class TripsController < ApplicationController def trip_params params.require(:trip).permit(:name, :started_at, :ended_at, :notes) end + + def to_boolean(value) + ActiveModel::Type::Boolean.new.cast(value) + end end