Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##new.rhtml
- <label name=center[country_id]>Country</label>
- <select name="center[country_id]" id="center_country_id">
- <option value="">-- Select Country --</option>
- <% @countries.each do |country| %>
- <option value=<%= country.id %>><%= country.name %>
- <% end %>
- </select>
- <div id="center_state_container">
- <%= render :partial => 'select_state'%></p>
- </div>
- <%= observe_field("center_country_id",
- :frequency => 1,
- :update => "center_state_container",
- :url => {:controller => 'center', :action =>'filtered_state_select',:method=>'post'},
- :with => "'country_id=' + escape(value)",
- :on=> 'click')%>
- <br>
- <center><%= submit_tag "Submit" %></center>
- ##CenterController.rb
- def filtered_state_select
- @states = State.find_all_by_country_id(params["country_id"])
- render :partial => 'select_state'
- end
- def filtered_city_select
- @cities = City.find_all_by_state_id(params["state_id"])
- render :partial => 'select_city'
- end
- ##_select_state.rhtml [partial]
- <% if @states %>
- <label name=center[state_id]>States:</label>
- <select name="center[state_id]" id="center_state_id">
- <option value="">-- Select State --</option>
- <% @states.each do |state| %>
- <option value=<%= state.id %>><%= state.name %>
- <% end %>
- </select>
- <% end %>
- <div id="center_city_container">
- <%= render :partial => 'select_city'%></p>
- </div>
- <%= observe_field("center_state_id",
- :frequency => 1,
- :update => "center_city_container",
- :url => {:controller => 'center', :action => 'filtered_city_select',:method=>'post'},
- :with => "'state_id=' + escape(value)",
- :on=> 'click')%>
- <br>
- ##_select_city.rhtml [partial]
- <br>
- <% if @cities %>
- <label name=center[city_id]>City:</label>
- <select name="center[city_id]" id="center_city_id">
- <option value="">-- Select City --</option>
- <% @cities.each do |city| %>
- <option value=<%= city.id %>><%= city.name %>
- <% end %>
- </select>
- <% end %>
Add Comment
Please, Sign In to add comment