mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
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
This commit is contained in:
parent
09b16ebd7f
commit
736aa15a1e
1 changed files with 7 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue