These are chat archives for dry-rb/chat

13th
Dec 2016
George Millo
@georgemillo
Dec 13 2016 11:54
is there any documentation for dry-view?
Valentin Trinqué
@ValentinTrinque
Dec 13 2016 16:07

Hi guys, I have some trouble using dry-validation. I am trying to ensure that some ids I receive from my API are actually valid records in my database. In my form I have this :

property sender_ids
required(:sender_ids) do
  filled? & array?
end
rule(valid_senders: [:sender_ids]) do |sender_ids|
   Contact.exists?(id: value(:sender_ids))
end

But it raises the following error :

POST /letters with valid data returns the new letter
Failure/Error:
  rule(valid_senders: [:sender_ids]) do |sender_ids|
    Contact.exists?(id: value(:sender_ids))
  end

NoMethodError: undefined method `with' for false:FalseClass
# ./.gems/gems/dry-validation-0.10.4/lib/dry/validation/schema/value.rb:96:in `rule'
# ./app/forms/letter/create_form.rb:31:in `block in <class:CreateForm>’

Do you have any idea ?

Valentin Trinqué
@ValentinTrinque
Dec 13 2016 16:30
I fixed the problem by creating a valid_contacts? function inside configure hook and call it from the required statement
Tim Riley
@timriley
Dec 13 2016 20:20
@georgemillo unfortunately no docs right now, we’re still figuring dry-view out a little bit. I hope to spend some of January on it and hopefully doc some things up then too.