Dependent dropdown lists - how to get them working

Hello,

I am new to Ruby and Rails.

I have a _form.html where there are 2 drop down lists. The first one
shows a list of categories and the second dropdown shows a list of
sub-categories.

How can I get the values of the second dropdown based on what the user
selected in the first dropdown list ?

Is the “merchant_account” object available in a variable in this form
automatically or do I have to create it by assignment ?


Business category: <%= options = [["Select a business category", ""]] + BusinessCategory.find_all.collect { |x| [x.business_category, x.id] } select("merchant_account", "business_category_fk", options ) %> Business sub category: <%= options = [["Select a business sub category", ""]] + select("merchant_account", "business_sub_category", options ) %>

Any help would be appreciated.