# Undefined method \`each\_with\_index'

**URL:** https://discourse.dry-rb.org/t/undefined-method-each-with-index/1381
**Category:** dry-validation
**Created:** [November 3, 2021, 9:38am UTC](https://discourse.dry-rb.org/t/undefined-method-each-with-index/1381 "2021-11-03T09:38:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![luckywine420](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/luckywine420/32/712_2.png) [@luckywine420](https://discourse.dry-rb.org/u/luckywine420)
#### Post date: [November 3, 2021, 9:38am UTC](https://discourse.dry-rb.org/t/undefined-method-each-with-index/1381/1 "2021-11-03T09:38:56Z")

</div>

Hi  
Let’s say I have this form:

```auto
class Form < Dry::Validation
  params do
    optional(:phones).maybe do
      each do
        hash do 
          required(:id).filled(:integer)
          required(:names).filled(:array, min_size?: 1) do 
             each(:integer)
          end
        end
      end
    end
  end

  rule(:phones).each do |index:|
    if values[:phones][index].dig(:id)
      key([:phones, index, :id]).failure("doesn't exist") unless check_id(values[:phones][index][:id])
    end
  end
end

```

given data:

```auto
data = {phones: nil}

```

I get an error when I try to validate my form:

```auto
form = Form.new
form.call(data) => Undefined method `each_with_index'

```

Do you know how Can I overcome this problem? I want phones to accept **nil** value. I’ve been thinking about overwriting #rule method but I don’t know where to start.

Thanks in advance!
