I''ve got a sortable list that you can add new elements to dynamically, using the prototype helpers (http://api.rubyonrails.org/classes/ ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/ GeneratorMethods.html) I want to be able to remove a selected item from the list dynamically -- presumably, each item in the list would have a link_to_remote that would pop a confirmation dialog, then remove the selected row from the list. When this happens, though, I will need to renumber all the other div id''s in my list to keep the list in good, numerical order. Any idea on how to rename a div id in this manner? I don''t want to replace the div outright, if possible, as that seems really messy. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Jan 24, 2011 at 12:45 PM, robo <chase.delanguillette-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I''ve got a sortable list that you can add new elements to dynamically, > using the prototype helpers (http://api.rubyonrails.org/classes/ > ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/<http://api.rubyonrails.org/classes/%0AActionView/Helpers/PrototypeHelper/JavaScriptGenerator/> > GeneratorMethods.html) > > I want to be able to remove a selected item from the list dynamically > -- presumably, each item in the list would have a link_to_remote that > would pop a confirmation dialog, then remove the selected row from the > list. When this happens, though, I will need to renumber all the > other div id''s in my list to keep the list in good, numerical order. >Why?> > Any idea on how to rename a div id in this manner? I don''t want to > replace the div outright, if possible, as that seems really messy. >Just an idea, but maybe you can leave the div''s as is --- when you remove a div then it just disappears, and the visible list order is still preserved. Then if the user does re-order the list at the ui, then you send ajax on that event.> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 24, 2011, at 1:45 PM, robo wrote:> I''ve got a sortable list that you can add new elements to dynamically, > using the prototype helpers (http://api.rubyonrails.org/classes/ > ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/ > GeneratorMethods.html) > > I want to be able to remove a selected item from the list dynamically > -- presumably, each item in the list would have a link_to_remote that > would pop a confirmation dialog, then remove the selected row from the > list. When this happens, though, I will need to renumber all the > other div id''s in my list to keep the list in good, numerical order.No, you really really don''t want to do this. Sortables use the actual ID of the related object to update the position column in the database for the appropriate records. If you''re using the sortable list helpers, you must have something like this in your view: <li id="''id_<%= whatever.id %>">,,,</li> And when you sort, the callback sends an array of these IDs back to the server in their current order. You do want to have a separate callback to remove the object from the collection you''re sorting, but that''s outside the scope of your sortable callback. Each time you update the position attribute in the database, you need to be doing that against a fresh lookup of your collection in your controller (so you won''t try to sort a missing element)[1]. And when you do, these IDs that are sent from the page must be the actual IDs of the elements, not some arbitrary numerical order values, or else you can''t update the correct elements with their new position value. Walter 1. def sort @categories = Category.all @categories.each do |category| category.position = params[''sort_list''].index(category.id.to_s) + 1 category.save end render :nothing => true end> > Any idea on how to rename a div id in this manner? I don''t want to > replace the div outright, if possible, as that seems really messy. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.