簡體   English   中英

AwesomeNestedSet + Rails 4.1.4`neested_set_options`拋出異常

[英]AwesomeNestedSet + Rails 4.1.4 `nested_set_options` throws exception

我有一個名為Collection的模型,配置如下:

acts_as_nested_set scope: :account, dependent: :destroy
belongs_to :parent, class_name: 'Collection'

使用nested_set_options視圖幫助程序工作正常,直到我升級到Rails 4.1.4(從4.0.5開始):

<%= f.input :parent_id, label: 'Parent Collection',
            collection: nested_set_options(@collections) { |collection|
              "#{'-' * collection.level} #{collection.name}"
            },
            include_blank: '-- No Parent --' %>

我得到這個例外:

undefined method `name' for nil:NilClass

/Users/cpeters/Sites/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb:45:in  `add_to_inverse_association'
/Users/cpeters/Sites/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb:37:in `block in associate_parents'
activerecord (4.1.4) lib/active_record/relation/delegation.rb:46:in `each'
activerecord (4.1.4) lib/active_record/relation/delegation.rb:46:in `each'
/Users/cpeters/Sites/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb:31:in `associate_parents'
/Users/cpeters/Sites/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb:33:in `block in nested_set_options'
/Users/cpeters/Sites/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb:32:in `each'
/Users/cpeters/Sites/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb:32:in `nested_set_options'
app/views/admin/resources/collections/_form.html.erb:7:in `block in _app_views_admin_resources_collections__form_html_erb__1427458998633439544_70350945783440'

這是從GitHub運行最新的(提交f823ffb )。

事實證明,我的belongs_to配置不是必需的,並且導致了問題。

我從模型中刪除了這一行,我的所有測試都通過了,應用程序正常工作:

belongs_to :parent, class_name: 'Collection'

我不確定我之前是否因為某種原因而把它放在那里,但我覺得連一行代碼都是一個勝利。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM