ActionView::Template::Error (no implicit conversion from nil to integer) - awesome_nested_set

1k Views Asked by At

I'm using awesome_nested_set to implement nested pattern in select tag. When there is no record in the database form is loading successfully, but after adding first category as base category whose parent_id is null this error is showing up

ActionView::Template::Error (no implicit conversion from nil to integer)

I've used view helper to implement this, my select tag looks like this

<%= f.select :parent_id, nested_set_options(Category, @category) {|i, level| "#{'-' * level} #{i.name}" } %>

Please help, how to get rid of this error, I'm using awesome nested set to implement this!

1

There are 1 best solutions below

0
On BEST ANSWER

You need to use this:

<%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>

You have a serious error in your block. As documented on the gem's page, the block passed to the nested_set_options only accepts a single argument i which is the category itself. level is a method of i which you can get using i.level.