# Combo box problem

**URL:** <https://www.ruby-forum.com/t/combo-box-problem/103823>\
**Category:** Rails\
**Created:** [May 10, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/combo-box-problem/103823 "2007-05-10T18:11:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cezar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dc4da7/32.png) [@Cezar](https://www.ruby-forum.com/u/Cezar)\
**Post date:** [May 10, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/combo-box-problem/103823/1 "2007-05-10T18:11:09Z")

</div>

Hi,

1st of all, my english is bad, and i’m new to RoR, so accept my  
apologies from start.  
I need two combo-boxes populated from two tables that will act as  
filters for a product list. I’ve already read some examples and  
tutorials, but it seems that I’m still stuck in the problem.

Files :  
db/migrate/001\_create\_products.rb [http://pastie.textmate.org/60449](http://pastie.textmate.org/60449)  
db/migrate/002\_create\_parent\_categories.rb  
[http://pastie.textmate.org/60452](http://pastie.textmate.org/60452)  
db/migrate/003\_create\_categories.rb [http://pastie.textmate.org/60453](http://pastie.textmate.org/60453)  
app/controllers/admin\_product\_controller.rb  
[http://pastie.textmate.org/60456](http://pastie.textmate.org/60456)  
app/views/admin\_product/list.rhtml [http://pastie.textmate.org/60458](http://pastie.textmate.org/60458)

the Controller for Products is called admin\_product. the list method  
takes all the products from the db\_table called products and displays  
them.  
the trick is to have two combo-boxes, 1st populated with the  
parent\_category\_name from the parent\_categories table, and the second  
populated with category\_name from the categories table. the default  
value in the combo-boxes should be “- Select a parent category -” and "

- Select a category -".  
When a option from the combo boxes is selected, the page should reload,  
displaying only the products that have the parent\_category\_id or the  
category\_id that was selected. and also, if a parent\_category is  
selected, the second combo box shoul display only the categories with  
the parent\_category\_id that was selected in the first combo-box. I think  
that the ajax example with state/county/city it’s not suitable, beacause  
the products list might be paginated. If I’m wrong please correct me.

Thank you for spendig this much time reading all this stuff and also for  
any hints and code snippets that I can use.

All my respect,  
Cezar

---

<div class="post-metadata">

**Author:** ![Cezar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dc4da7/32.png) [@Cezar](https://www.ruby-forum.com/u/Cezar)\
**Post date:** [May 11, 2007, 7:19am UTC](https://www.ruby-forum.com/t/combo-box-problem/103823/2 "2007-05-11T07:19:00Z")

</div>

Hi,

the effect could be seen here ;  
[http://shop.elsaco.com/ais2002/shop/page.php?third=20-inch&third2=Monitors%20LCD%20\<B\>ViewSonic\</B\>](http://shop.elsaco.com/ais2002/shop/page.php?third=20-inch&third2=Monitors%20LCD%20%3CB%3EViewSonic%3C/B%3E)

when you select the subcategories : size in inch the list gets  
refreshed.

All my respect,  
Cezar

---

<div class="post-metadata">

**Author:** ![Cezar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dc4da7/32.png) [@Cezar](https://www.ruby-forum.com/u/Cezar)\
**Post date:** [May 11, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/combo-box-problem/103823/3 "2007-05-11T17:40:44Z")

</div>

Hi,

I’ve wrote in the list.rhtml this piece of code  
\<%=  
collection\_select(:categories, :id, @categories, :id,  
:category\_name,  
options = {:prompt =\> ‘- Select Parent Category -’},  
html\_options = {:onChange =\> “remote\_function :url =\>  
{:controller =\> ‘admin\_product’, :action =\> ‘list’}, :with =\>  
‘Form.Element.serialize(this)’”})  
%\>

but it’s not working. Any ideas ?  
1st of all, prompt should put ‘- Select Parent Category -’ in the  
options, and it’s not working,  
2nd of all, if i do collection\_select(:categories, :category\_name,  
@categories, :id, :category\_name,  
it says

undefined method `category\_name’ for #Array:0x3525f8c

I’ve got 2 days now sience i’m stuck with this problem at my diploma  
project.  
All my respect,  
Cezar
