These are chat archives for dry-rb/chat

18th
Sep 2018
Sean Winner
@swinner2
Sep 18 2018 18:12

I have params {foo: [“”]}

for a select box where the user doesnt select anything.
I want this to fail.
optional(:foo).each { filled? }
This rule works but gives me an error message like this 0=>["must be filled”]

Is there any way to have an error message like ["must be filled”]

Sean Winner
@swinner2
Sep 18 2018 19:31

I was able to get around it by doing

    validate(valid_foo: :foo) do |foo|
      if foo
        if foo.first.present?
          true
        else
          false
        end
      else
        true
      end
    end

but I figured people may have run into this problem before

Grant Shangreaux
@gcentauri
Sep 18 2018 20:06
i assume that is happening because it is validating each index in the array, and is trying to let you know which index failed validation.