繁体   English   中英

Ruby on Rails:干模式干验证未验证存在

[英]Ruby on Rails: dry-schema dry-validation not validating presence

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

我在Rails应用程序中使用dry-validation和dry-schema,并实现建议以检查如何检查title属性的存在。 但是,完成上述操作后,仍然会说

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

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

以下是发送的原始参数,其中明显包含“ 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"

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM