Refactor: Use proper boolean casting for sharing parameters

- Replace string comparisons ('1', '0') with ActiveModel::Type::Boolean
- More robust handling of truthy/falsy values
- Follows Rails conventions for type coercion
- HTML forms still send string values, but controller properly converts them
This commit is contained in:
Claude 2025-11-07 12:52:30 +00:00
parent 53ec557ec9
commit 09b16ebd7f
No known key found for this signature in database

View file

@ -74,11 +74,11 @@ class TripsController < ApplicationController
def handle_sharing_update
sharing_params = params[:trip][:sharing]
if sharing_params[:enabled] == '1'
if ActiveModel::Type::Boolean.new.cast(sharing_params[:enabled])
sharing_options = {
expiration: sharing_params[:expiration] || '24h',
share_notes: sharing_params[:share_notes] == '1',
share_photos: sharing_params[:share_photos] == '1'
share_notes: ActiveModel::Type::Boolean.new.cast(sharing_params[:share_notes]),
share_photos: ActiveModel::Type::Boolean.new.cast(sharing_params[:share_photos])
}
@trip.enable_sharing!(**sharing_options)