1
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"
solnic
  • 5,733
  • 2
  • 23
  • 19
zasman
  • 446
  • 1
  • 8
  • 28

1 Answers1

4

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

solnic
  • 5,733
  • 2
  • 23
  • 19
  • 1
    Thanks, adding `params.require("data").permit!.to_h` works. – zasman Jul 30 '19 at 17:50
  • @solnic I've searched the dry-validation docs and there is no info about that. Are there any docs how to use dry-validation gem with Rails? Or maybe the gem is designed to work mainly with Hanami framework? – Greg Dan Oct 18 '19 at 08:05
  • 2
    @GregDan not yet but I plan to start a dry-rails project that will integrate various dry-rb gems with rails and it'll include support for dry-validation. – solnic Oct 21 '19 at 07:57