1
module QleKinds
  class CreateParamsValidator < MyCustomClass
    define do
      required(:title).value(:filled?)
    end
  end
end

我在 Rails 应用程序中使用干验证和干模式并实施建议以检查如何检查title属性的存在。尽管如此,在完成上述操作后,它仍然说

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

但是,标题属性肯定包含在发送的原始参数中。有人有什么建议吗?

以下是发送的原始参数,其中明确包括“标题”:

[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"
4

1 回答 1

3

ActionController::Parameters不支持,您需要先将它们强制为哈希。

于 2019-07-30T16:29:43.480 回答