# Sort the collection in the index.rhtml

**URL:** <https://www.ruby-forum.com/t/sort-the-collection-in-the-index-rhtml/132170>\
**Category:** Rails\
**Created:** [March 17, 2008, 4:08pm UTC](https://www.ruby-forum.com/t/sort-the-collection-in-the-index-rhtml/132170 "2008-03-17T16:08:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kei\_Simone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@Kei\_Simone](https://www.ruby-forum.com/u/Kei_Simone)\
**Post date:** [March 17, 2008, 4:08pm UTC](https://www.ruby-forum.com/t/sort-the-collection-in-the-index-rhtml/132170/1 "2008-03-17T16:08:23Z")

</div>

Hi,

i am using rails 1.2.6 please forgive me as this application is live  
and i could not find the time to move it to rails 2.0

i have a index.rhtml for items

item has 3 attributes other than id, they are name, category and size

current status =\>

inside the index.rhtml

i obviously already display my data as below:

name category size  
a mugs L  
aa mugs M  
abc towels L  
bb toothpaste S

what i need now is an additional drop down list that will contain all  
possible categories of the products

so if i choose let say, mugs from the drop down list the whole page  
can either using ajax to refresh the list to contain just mugs or do a  
refresh of the page.

this drop down not only needs to include teh varioous categories but  
also the word ‘All’ so that if the user chooses All , the list will  
again display all items in database.

Can someone please enlighten me on how to do this?

Thank you.

---

<div class="post-metadata">

**Author:** ![Kei\_Simone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@Kei\_Simone](https://www.ruby-forum.com/u/Kei_Simone)\
**Post date:** [March 17, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/sort-the-collection-in-the-index-rhtml/132170/2 "2008-03-17T16:20:00Z")

</div>

You mean to say you want to create a dynamic drop down in which if a  
category is changed then the other drop down should be filled  
accordingly??

---

<div class="post-metadata">

**Author:** ![Kei\_Simone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/839c29/32.png) [@Kei\_Simone](https://www.ruby-forum.com/u/Kei_Simone)\
**Post date:** [March 20, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/sort-the-collection-in-the-index-rhtml/132170/3 "2008-03-20T16:38:58Z")

</div>

Hi,

I meant that i only want 1 drop down.

depending on what i chose in that drop down list, i will display items  
based on drop down.

that drop down will include all possible categories as well as teh  
value “All”

eg:

if i have just 5 items,

item 1 category is mugs  
item 2 category is mugs  
item 3 category is towels  
item 4 category is towels  
item 5 category is cups

if i chose all in that drop down, the page will display items 1 - 5  
if i chose mugs in the drop down, the page will display items 1 - 2  
if i chose towels in the drop down, the page will display items 3 - 4  
if i chose cups in the drop down, the page will display items 5

Please advise.

Thank you.
