I need help with my 1st sortable list!

Ill keep it brief. Dragging an item is working but dropping and
updating the list gives me this error -

NoMethodError in AdminController#sort

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each

#{RAILS_ROOT}/app/controllers/admin_controller.rb:171:in `sort’

My view -

    <% @prices.each do |@price| %>
  • <%= @price.service %> <%= @price.price %>
  • <% end %>

<%= sortable_element ‘price’,
:update => ‘list-info’,
:url => { :action => “sort”, :id => @price },
:complete => visual_effect(:highlight, ‘pricelist’)
%>

Controller -

def sort
@price = Price.find(params[:price])
@prices.each do |@price|
@price.position = params[‘price’].index(@price.id.to_s) + 1
@price.save
end
render :nothing => true
end

Model -

class Price < ActiveRecord::Base
belongs_to :user
acts_as_list :scope => :user
end

Hi Rob,

I’m guessing it’s late where ever you’re writing from :wink:

Rob B. wrote:

NoMethodError in AdminController#sort
#{RAILS_ROOT}/app/controllers/admin_controller.rb:171:in `sort’

My view -

Why are you looking at the view? Rails gave you the two lines above
telling
you to look in your controller. One of them even tells you what line
number
in the controller, and what method it’s in in case your editor doesn’t
show line numbers.

You have a nil object when you didn’t expect it!

The error occured while evaluating nil.each

Any occurrances of “.each” in the code below?

def sort
@price = Price.find(params[:price])
@prices.each do |@price|
@price.position = params[‘price’].index(@price.id.to_s) + 1
@price.save
end
render :nothing => true
end

You’re not assigning anything to @prices before you try to enumerate
it’s
elements.

Best regards,
Bill

You’re not assigning anything to @prices before you try to enumerate
it’s
elements.

I’m not following sorry. What do I need to assign?