On Jul 12, 2005, at 12:39 PM, David Kerley wrote:
> only just found the script.aculo.us site. brilliant. much respect.
>
Here, here. Much respect.
>
> wondered if anyone can point me in the right direction on this drag
> and drop
> list re-ordering type thing, i''ve read through what I can but to
be
> honest
> it''s gone right over my head!
>
David, check this answer(s) to your question, basically, from the
main Rails list:
> My quick and dirty solution is to
>
> @thing_ids = params[:things]
> @thing_ids.each do |thing_id|
> Thing.find(thing_id).move_to_bottom
> end
>
> But that''s rather inefficient, and quite slow when you''re
ordering
> large lists.
>
>
class Thing < ActiveRecord::Base
def self.reorder( things )
things.each do |thing_id|
thing = find thing_id
thing.send "#{position_column}=".to_sym, things.index( thing_id
)
thing.save
end
end
end
The last one comes with a caveat that it hasn''t been tested. The
first (quick and dirty) one I implemented yesterday and it worked
fine. I did a bit of work to integrate it with the examples on the
scriptaculous site... basically what it does is go thru and push
everything to the "end" of the list, which is inefficient, but I
can''t think of a better way...
I plan on moving to the second implementation this week because it
moves the responsibility to the model, rather than the controller,
where it belongs. Or so I''m told. :)
Hope it works for you!
-raymond