State select box to be populated according to country

Hi
I have the models company,country, state
company belongs_to country
country has_many states
state belongs_to country

   In my company creation view i have two select boxes for country

and state. I could implement the country select like

<% form_for @company do |f| %>
<%= f.collection_select :country_id, Country.all, :id,:name,{},{} %>

  Upon submit country is save with company .This is working. Now I

dont know how to populate the state And also I have to change the state
select box according to change in country.Please guide me

Thanks
Tom

Hi

Ryan B. got a railscasts episode that deals with this exact case:
http://railscasts.com/episodes/88-dynamic-select-menus
Thanks for your reply. I have tried this But is not working My rails
version is 2.3.5 I have added map.connect
‘:controller/:action/:id.:format’
to routes.r as suggested. But in any way I cant access
http://localhost:3001/javascripts/dynamic_states.js
I am getting

Routing Error

No route matches “/javascripts/dynamic_states.js” with {:method=>:get}

Tom

Ryan B. got a railscasts episode that deals with this exact case:
http://railscasts.com/episodes/88-dynamic-select-menus

You need to but dynamic_states.js in your public/javascripts folder.

–Lasse

2010/2/15 Tom M. [email protected]

On Feb 15, 1:18 am, Tom M. [email protected] wrote:

Hi
I have the models company,country, state

You might avoid a lot of work by using the Carmen plugin (or one like
it):
http://github.com/jim/carmen


Kurt W.
I am looking for a new rails job:
http://www.CircleW.org/kurt/pages/resume

Lasse B. wrote:

You need to but dynamic_states.js in your public/javascripts folder.

–Lasse

But how is it possible? In screencast it is dynamic_states.js.erb
that contains both ruby and javascript code. So how can i put that to
public/javascripts?

Tom

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