Ruby on Rails: dry-schema dry-validation not validating presence

1.5k Views Asked by At
module QleKinds
  class CreateParamsValidator < MyCustomClass
    define do
      required(:title).value(:filled?)
    end
  end
end

I'm using dry-validation and dry-schema in a rails application and implementing the advice to check how to check for the presence of the title attribute. Nonetheless, after doing the above, it still says

#<Dry::Schema::Result{} errors={:title=>["is missing"]

However, the title attribute is definitely included in the original params being sent. Anyone have any advice?

Here are the original params sent, which clearly include 'title':

[1] pry(#<Admin::QleKinds::CreateService>)> qle_kind_data
=> <ActionController::Parameters {"effective_on_kinds"=>["date_of_event"], "end_on"=>"06/01/2005", "event_kind_label"=>"Date of birth", "is_self_attested"=>"true", "market_kind"=>"shop", "post_event_sep_in_days"=>"1", "pre_event_sep_in_days"=>"1", "questions_attributes"=><ActionController::Parameters {"0"=><ActionController::Parameters {"answer_attributes"=><ActionController::Parameters {"responses_attributes"=><ActionController::Parameters {"0"=><ActionController::Parameters {"name"=>"true", "result"=>"contact_call_center"} permitted: true>, "1"=><ActionController::Parameters {"name"=>"false", "result"=>"contact_call_center"} permitted: true>, "2"=><ActionController::Parameters {"operator"=>"before", "value"=>"", "value_2"=>""} permitted: true>, "3"=><ActionController::Parameters {"name"=>"", "result"=>"proceed"} permitted: true>} permitted: true>} permitted: true>, "content"=>"When was Your Dog Born?", "type"=>"date"} permitted: true>} permitted: true>, "reason"=>"birth", "start_on"=>"06/01/1990", "title"=>"Got a New Dog", "tool_tip"=>"Household adds a new dog for emotional support"} permitted: true>
[2] pry(#<Admin::QleKinds::CreateService>)> qle_kind_data["title"]
=> "Got a New Dog"
1

There are 1 best solutions below

3
On

ActionController::Parameters are not supported, you need to coerce them to a hash first.