# Sorting(and updating) multiple lists on one page

**URL:** <https://www.ruby-forum.com/t/sorting-and-updating-multiple-lists-on-one-page/109713>\
**Category:** Rails\
**Created:** [July 18, 2007, 8:06am UTC](https://www.ruby-forum.com/t/sorting-and-updating-multiple-lists-on-one-page/109713 "2007-07-18T08:06:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty669](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/e47c2d/32.png) [@qwerty669](https://www.ruby-forum.com/u/qwerty669)\
**Post date:** [July 18, 2007, 8:06am UTC](https://www.ruby-forum.com/t/sorting-and-updating-multiple-lists-on-one-page/109713/1 "2007-07-18T08:06:19Z")

</div>

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 %\>

  
\<% for todo in list.todos.sort{|a,b| a.position \<=\> b.position} %\>  
-   
\<%= todo.content %\>  
  
\<% end %\>  

\<% end %\>

Notice that im using above: Sortable.create(“listAjax\<%= list.id %\>” …  
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:

...
...
... 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  
them?

Any help, really cause this its driving me nuts.

---

<div class="post-metadata">

**Author:** ![qwerty669](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/e47c2d/32.png) [@qwerty669](https://www.ruby-forum.com/u/qwerty669)\
**Post date:** [July 19, 2007, 10:01am UTC](https://www.ruby-forum.com/t/sorting-and-updating-multiple-lists-on-one-page/109713/2 "2007-07-19T10:01:10Z")

</div>

No one, its really that hard?

---

<div class="post-metadata">

**Author:** ![qwerty669](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/e47c2d/32.png) [@qwerty669](https://www.ruby-forum.com/u/qwerty669)\
**Post date:** [July 19, 2007, 10:24am UTC](https://www.ruby-forum.com/t/sorting-and-updating-multiple-lists-on-one-page/109713/3 "2007-07-19T10:24:55Z")

</div>

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  
end  
end

Cheers,  
Chris

On Jul 19, 6:01 pm, Evan T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
