Forum: Ruby on Rails Sorting(and updating) multiple lists on one page

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ca2e3e3f873fed864da130efb194e199?d=identicon&s=25 Evan Thomas (evansev)
on 2007-07-18 08:06
Hi people, ive been searching for a while and i cant find a solution for
this, im making a todo list with sortable items(and updated its position
on the server), it works very good when i have only one list but when i
have more than one the items are sorted in the view but not get
updated(at least all but one) and ill try to explain why so hope you can
give me a hand:

On the view i have this(all working):

<% for list in @lists %>
    <ul id="listAjax<%= %>">
    <% for todo in list.todos.sort{|a,b| a.position <=> b.position} %>
    <li id="item_<%= %>">
      <%= todo.content %>
    <% end %>

  <script type="text/javascript">
  Sortable.create("listAjax<%= %>", {onUpdate:function(){new
Ajax.Request('/todos/repeat', {asynchronous:true, evalScripts:true,
parameters:Sortable.serialize("listAjax<%= %>")})}})

<% end %>

Notice that im using above: Sortable.create("listAjax<%= %>" ...
that way the lists are named diferently, non repeated with its id.

An in the controller i catch the para meters like this:

order = params[:listAjax]
#all the rest of the ordering process...

So here its the problem the lists are generated like this:
<ul id="listAjax1">...
<ul id="listAjax2">...
<ul id="listAjax3">...
when theres just one list i can cath its parameters with(for the first):
order =  params[:listAjax1]

but when theres more list i dont know how, so the main question is, how
i can cath the parameters of the multiple lists(one at the time of
course while reordering its items) in the controller so i can update

Any help, really cause this its driving me nuts.
Ca2e3e3f873fed864da130efb194e199?d=identicon&s=25 Evan Thomas (evansev)
on 2007-07-19 10:01
No one, its really that hard?
B1112061b921903a0b337e10048798af?d=identicon&s=25 Chris (Guest)
on 2007-07-19 10:24
(Received via mailing list)
If I understand correctly, the problem is that you don't know in your
action whether to expect params[:itemlist1], or params[:itemlistN].
You could try something like:

params.to_a.each do |key, value|
  if key.index('itemlist') == 0
    order =  params[key]
    # Process the order


On Jul 19, 6:01 pm, Evan Thomas <>
This topic is locked and can not be replied to.