# Drag and drop sorting recipe

**URL:** <https://www.ruby-forum.com/t/drag-and-drop-sorting-recipe/55785>\
**Category:** Rails\
**Created:** [March 23, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/drag-and-drop-sorting-recipe/55785 "2006-03-23T21:15:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![larrywright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9fc348/32.png) [@larrywright](https://www.ruby-forum.com/u/larrywright)\
**Post date:** [March 23, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/drag-and-drop-sorting-recipe/55785/1 "2006-03-23T21:15:42Z")

</div>

The new pragmatic Rails Cookbook has a drag and drop sorting recipe.  
Does  
anyone know if this works with 1.0?

I’ve followed the recipe (i think), and I can drag but when I drop  
everything goes back the way it was. It seems that the sort logic  
doesn’t  
get invoked.

I put this code in my view:

```
<%= sortable_element 'task-list' ,
    :url => { :action => "sort", :id => @user },
    :complete => visual_effect(:highlight, 'task-list' )
%>

```

which leads to this in the HTML:

//

but the sort method doesn’t get invoked on the drop. Any idea why?

thanks.

---

<div class="post-metadata">

**Author:** ![larrywright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9fc348/32.png) [@larrywright](https://www.ruby-forum.com/u/larrywright)\
**Post date:** [March 24, 2006, 12:03am UTC](https://www.ruby-forum.com/t/drag-and-drop-sorting-recipe/55785/2 "2006-03-24T00:03:03Z")

</div>

On 3/23/06, Larry W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The new pragmatic Rails Cookbook has a drag and drop sorting recipe. Does  
> anyone know if this works with 1.0?
> 
> I’ve followed the recipe (i think), and I can drag but when I drop  
> everything goes back the way it was. It seems that the sort logic doesn’t  
> get invoked.
> 
> Larry, this indeed does work with 1.0. Eliminate the easy stuff first–  
> check that you have acts\_as\_list in your model, a position field in your  
> table, and, of course, javascript\_include\_tag :defaults somewhere in  
> your  
> view.

HTH,  
Dean

---

<div class="post-metadata">

**Author:** ![larrywright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9fc348/32.png) [@larrywright](https://www.ruby-forum.com/u/larrywright)\
**Post date:** [March 24, 2006, 1:43am UTC](https://www.ruby-forum.com/t/drag-and-drop-sorting-recipe/55785/3 "2006-03-24T01:43:38Z")

</div>

I have all those things setup. This is my model:

class TaskItem \< ActiveRecord::Base  
belongs\_to :task  
belongs\_to :person  
acts\_as\_list :scope =\> :person  
end

This is the table:

CREATE TABLE task\_item  
( person\_id int4 NOT NULL,  
“position” int4 NOT NULL,  
task\_id int4 NOT NULL)

and the defaults tag is there. It causes three javascript files to be  
loaded:

Any ideas on what to try next?

---

<div class="post-metadata">

**Author:** ![larrywright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9fc348/32.png) [@larrywright](https://www.ruby-forum.com/u/larrywright)\
**Post date:** [March 24, 2006, 1:48am UTC](https://www.ruby-forum.com/t/drag-and-drop-sorting-recipe/55785/4 "2006-03-24T01:48:51Z")

</div>

Ok - it was working. I had been grabbing the list items by the list  
item  
symbol, and it worked for dragging but not dropping. As long as I grab  
the  
item by its name, the drop works - strange.

Thanks for your help.
