I''m trying to figure out a good way to get acts_as_list and the new sortable lists to play nicely together, but they don''t seem like they''re designed to mesh well. The ajax sortable lists post a complete ordered list of ids back to the server after every change, but acts_as_list is designed to deal with diff-like changes, rather than reordering the whole list from scratch. 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. Any better ideas? Tyler
On 7/7/05, Tyler Kiley <tyler.kiley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 I haven''t tested the above code -- it''s just off the top of my head. YMMV It''s probably no more efficient than what you are doing now, but at least it keeps the logic in the model class where it belongs (and is generic enough that you could put the ''reorder'' method in a module and include it in classes that need it). -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland
On Jul 7, 2005, at 11:37 AM, Tyler Kiley wrote:> I''m trying to figure out a good way to get acts_as_list and the new > sortable lists to play nicely together, but they don''t seem like > they''re designed to mesh well. The ajax sortable lists post a > complete ordered list of ids back to the server after every change, > but acts_as_list is designed to deal with diff-like changes, rather > than reordering the whole list from scratch.This seems like a great topic for a tutorial or best-practices document, is there such a tutorial or document? I would greatly appreciate it! Best, Raymond