Ruby on rails ActionView::Template::Error(没有从nil到integer的隐式转换)-awesome\u嵌套\u集

Ruby on rails ActionView::Template::Error(没有从nil到integer的隐式转换)-awesome\u嵌套\u集,ruby-on-rails,ruby-on-rails-4,nested,acts-as-nested-set,Ruby On Rails,Ruby On Rails 4,Nested,Acts As Nested Set,我正在使用来实现select标记中的嵌套模式。当数据库表单中没有记录成功加载时,但在将第一个类别添加为父类id为null的基本类别后,将显示此错误 ActionView::Template::Error (no implicit conversion from nil to integer) 我已经使用view helper实现了这一点,我的select标记如下所示 <%= f.select :parent_id, nested_set_options(Category, @catego

我正在使用来实现select标记中的嵌套模式。当数据库表单中没有记录成功加载时,但在将第一个类别添加为父类id为null的基本类别后,将显示此错误

ActionView::Template::Error (no implicit conversion from nil to integer)
我已经使用view helper实现了这一点,我的select标记如下所示

<%= f.select :parent_id, nested_set_options(Category, @category) {|i, level| "#{'-' * level} #{i.name}" } %>
请帮助,如何摆脱这个错误,我使用可怕的嵌套集来实现这一点

您需要使用以下选项:

<%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
您的区块中有一个严重错误。正如gem页面上记录的那样,传递给嵌套的_set_选项的块只接受一个参数i,即类别本身。level是一种i方法,您可以使用i.level获得该方法