2013-11-22 58 views
1

我使用awesome_nested_set在select標籤中實現嵌套模式。當有數據庫形式沒有記錄被成功加載,但增加第一類是基礎類,其PARENT_ID爲空後此錯誤顯示出來ActionView :: Template :: Error(沒有從nil到整數的隱式轉換) - awesome_nested_set

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

我使用視圖助手來實現這一點,我的選擇標籤看起來像這樣

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

請幫忙,如何擺脫這個錯誤,我使用真棒嵌套集來實現這個!

回答

3

您需要使用這樣的:

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

你在你的塊有一個嚴重的錯誤。正如在寶石的頁面上所記錄的,傳遞給nested_set_options的塊只接受一個參數i,這是該類別本身。 level是一個i的方法,您可以使用i.level

+0

感謝您清除我的疑惑 – RSB

相關問題