Forum: Ruby on Rails drag and drop sorting recipe

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Larry W. (Guest)
on 2006-03-23 22:15
(Received via mailing list)
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:

//<![CDATA[
Sortable.create('task-list',
   {onUpdate:function()
     {new Ajax.Request('/tasklists/sort/101',
      {asynchronous:true, evalScripts:true, onComplete:function(request)
        {new Effect.Highlight('task-list',{});},
parameters:Sortable.serialize('task-list')})}})
//]]>

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


thanks.
Howard R. (Guest)
on 2006-03-24 01:03
(Received via mailing list)
On 3/23/06, Larry W. <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
Larry W. (Guest)
on 2006-03-24 02:43
(Received via mailing list)
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:

<script src="/javascripts/effects.js" type="text/javascript"></script>
<script src="/javascripts/dragdrop.js" type="text/javascript"></script>
<script src="/javascripts/controls.js" type="text/javascript"></script>

Any ideas on what to try next?
Larry W. (Guest)
on 2006-03-24 02:48
(Received via mailing list)
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.
This topic is locked and can not be replied to.