# I need help with my 1st sortable list!

**URL:** <https://www.ruby-forum.com/t/i-need-help-with-my-1st-sortable-list/62322>\
**Category:** Rails\
**Created:** [June 2, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/i-need-help-with-my-1st-sortable-list/62322 "2006-06-02T18:24:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 2, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/i-need-help-with-my-1st-sortable-list/62322/1 "2006-06-02T18:24:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 2, 2006, 7:11pm UTC](https://www.ruby-forum.com/t/i-need-help-with-my-1st-sortable-list/62322/2 "2006-06-02T19:11:14Z")

</div>

Hi Rob,

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

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

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 5, 2006, 10:55am UTC](https://www.ruby-forum.com/t/i-need-help-with-my-1st-sortable-list/62322/3 "2006-06-05T10:55:52Z")

</div>

> 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?
