Combo box problem

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
db/migrate/002_create_parent_categories.rb
http://pastie.textmate.org/60452
db/migrate/003_create_categories.rb http://pastie.textmate.org/60453
app/controllers/admin_product_controller.rb
http://pastie.textmate.org/60456
app/views/admin_product/list.rhtml 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

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>

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

All my respect,
Cezar

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs