I have a model called Collection
that is configured as such:
acts_as_nested_set scope: :account, dependent: :destroy
belongs_to :parent, class_name: 'Collection'
Using the nested_set_options
view helper worked fine until I upgraded to Rails 4.1.4 (up from 4.0.5):
<%= f.input :parent_id, label: 'Parent Collection',
collection: nested_set_options(@collections) { |collection|
"#{'-' * collection.level} #{collection.name}"
},
include_blank: '-- No Parent --' %>
I get this exception:
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'
This is running the latest from GitHub (commit f823ffb).
As it turns out, my belongs_to
configuration was not needed and was causing the problem.
I removed this line from the model, and all of my tests are passing, and the app works fine:
belongs_to :parent, class_name: 'Collection'
Not sure if I put that in there for a reason earlier, but I feel that having even one line less of code is a victory.