I am using the Ancestry Gem and I am getting an undefined method "arrange" for #<Array:0x007f8d58e58700> error with the following code:
<%= @shipmgr_carriers.arrange(:order => :name) %>
However, When I just output @shipmgr_carriers I get an array with ancestry:
[#<Shipmgr::Carrier id: 9, name: "testing", status: nil, created_at: "2012-01-16 22:44:28", updated_at: "2012-01-16 22:44:28", ancestry: nil>, #<Shipmgr::Carrier id: 10, name: "test", status: nil, created_at: "2012-01-16 22:44:28", updated_at: "2012-01-16 22:44:28", ancestry: "9">]
Can anyone tell me why I am unable to call the .arrange method on the array variable?
I haven’t used Ancestry but it looks like it adds the
arrangemethod to ActiveRecord::Base. It doesn’t add this method to Array and so you shouldn’t expect it to work on an array.I’m assuming you’re declaring
@shipmgr_carriersin your controller something like this:Try this instead:
My hunch is that by the time
@shipmgr_carriersgets to your view the query has already been run, transforming it into an array of results instead of a relation.This is logic that should probably be done in the controller anyway, so moving it out of the view is a good idea regardless.