Module: StructuredParams::Validations
- Extended by:
- ActiveSupport::Concern
- Included in:
- Params
- Defined in:
- lib/structured_params/validations.rb
Overview
Provides validates_raw which validates raw parameter values before type casting.
Internally delegates to ActiveModel’s validates on the _before_type_cast attribute, then remaps errors back to the original attribute name. This means all standard ActiveModel validators (format, numericality, etc.) work as-is on the raw input value.
Example:
class UserParams < StructuredParams::Params
attribute :age, :integer
validates_raw :age, format: { with: /\A\d+\z/, message: 'must be numeric string' }
end
params = UserParams.new(age: "abc")
params.valid? # => false
params.errors[:age] # => ["must be numeric string"]