# Filter collection based on field value in the index.rhtml

**URL:** <https://www.ruby-forum.com/t/filter-collection-based-on-field-value-in-the-index-rhtml/132849>\
**Category:** Rails\
**Created:** [March 25, 2008, 10:00am UTC](https://www.ruby-forum.com/t/filter-collection-based-on-field-value-in-the-index-rhtml/132849 "2008-03-25T10:00:12Z")\
**Posts on this page:** 1\
**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 25, 2008, 10:00am UTC](https://www.ruby-forum.com/t/filter-collection-based-on-field-value-in-the-index-rhtml/132849/1 "2008-03-25T10:00:12Z")

</div>

Hi,

I am using Rails 1.2.6

i have an items controller.

i am using the templated index.rhtml so it displays everything in my  
items table

each item has the following fields in database.  
id  
name  
category which is non unique  
price

what i need is let say there is a drop down list in the index.rhtml  
which contains all the possible values of category in the items table.  
(I have managed this.)

inside this drop down list it contains say 3 possible values of  
category and the value ‘ALL’

when a user chooses the value in the drop down, i need the items that  
are displayed in this index.rhtml to change accordingly.

Eg, if the user chooses the category ‘household’

the page will only display items whose category is of the value  
household.

if the user chooses ‘ALL’

the page will display all.

I am open to either ajax or a full postback. Please advise me as to  
how to get the effect I want.

Please advise.

Thank you.
