File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ Use `validates_raw` to validate the original input value before type casting.
3232class UserParams < StructuredParams ::Params
3333 attribute :age , :integer
3434
35+ # Validate raw input before type casting to avoid accepting partially numeric strings (e.g. "12x").
3536 validates_raw :age , format: { with: /\A\d +\z / , message: ' must be numeric string' }
3637end
3738
Original file line number Diff line number Diff line change @@ -10,9 +10,13 @@ module StructuredParams
1010 # Strong Parameters example (API):
1111 # class UserParams < StructuredParams::Params
1212 # attribute :name, :string
13+ # attribute :age, :integer
1314 # attribute :address, :object, value_class: AddressParams
1415 # attribute :hobbies, :array, value_class: HobbyParams
1516 # attribute :tags, :array, value_type: :string
17+ #
18+ # # Validate raw input before type casting (e.g., "12x" for integer fields)
19+ # validates_raw :age, format: { with: /\A\d+\z/, message: 'must be numeric string' }
1620 # end
1721 #
1822 # # In controller:
You can’t perform that action at this time.
0 commit comments