views:

30

answers:

1

Dear All,

I am using two collection_select

Views

<%= collection_select(@table, "gm", @strs, "country", "country", {:prompt => "Select Country"}) %>
<%= submit_tag value="Proceed-->"%> 

<%= collection_select(@table, "sp", @pops, "state", "state", {:prompt => "Select State"}) %>
<%= submit_tag value="Submit"%>  

Controller

@strs = Table.find_by_sql("SELECT DISTINCT country FROM tables ORDER BY country")

@pops = Table.find(:all, :conditions=>{:country => params[:gm]}, :order=> 'state', :select=> 'DISTINCT state')

Here, these are relational collection_select. I need to populate the second collection_select once first collection_select was selected. Now I am using submit key. But, once "Proceed" submit was processed, params[gm] was disabled. So I am unable to process "Submit" tag with both params[gm] and params[sp] for @table.

I found some idea to create dynamic collection_select using javascript. But, I need to populate dynamically or single time processing of relational params[gm] and params[sp] using rails alone. please anyone help me.

+1  A: 

It looks like this is what you're looking for
Country-State Select Using Carmen and jQuery

Hoa
Hoa: Yaa... Exactly as mentioned.. but, I need to apply this concept without javascripts. Any idea with Rails?
Palani Kannan
Even if you want to implement the feature on the server side, some JavaScript is required. To be specific, when a user selects a country, you have to submit the form to obtain the corresponding states. And the form submission here will be triggered by JavaScript onchange event.
Hoa