1

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!

Chandranshu
  • 3,669
  • 3
  • 20
  • 37
Rajdeep Singh
  • 17,621
  • 6
  • 53
  • 78

1 Answers1

3

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.

Chandranshu
  • 3,669
  • 3
  • 20
  • 37