Guest User

Untitled

a guest
Apr 26th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. ##new.rhtml
  2.  
  3. <label name=center[country_id]>Country</label>
  4.  
  5. <select name="center[country_id]" id="center_country_id">
  6. <option value="">-- Select Country --</option>
  7. <% @countries.each do |country| %>
  8. <option value=<%= country.id %>><%= country.name %>
  9. <% end %>
  10. </select>
  11.  
  12. <div id="center_state_container">
  13. <%= render :partial => 'select_state'%></p>
  14. </div>
  15.  
  16. <%= observe_field("center_country_id",
  17. :frequency => 1,
  18. :update => "center_state_container",
  19. :url => {:controller => 'center', :action =>'filtered_state_select',:method=>'post'},
  20. :with => "'country_id=' + escape(value)",
  21. :on=> 'click')%>
  22.  
  23. <br>
  24. <center><%= submit_tag "Submit" %></center>
  25.  
  26.  
  27.  
  28. ##CenterController.rb
  29.  
  30. def filtered_state_select
  31. @states = State.find_all_by_country_id(params["country_id"])
  32. render :partial => 'select_state'
  33. end
  34.  
  35. def filtered_city_select
  36. @cities = City.find_all_by_state_id(params["state_id"])
  37. render :partial => 'select_city'
  38. end
  39.  
  40.  
  41. ##_select_state.rhtml [partial]
  42.  
  43. <% if @states %>
  44. <label name=center[state_id]>States:</label>
  45. <select name="center[state_id]" id="center_state_id">
  46. <option value="">-- Select State --</option>
  47.  
  48. <% @states.each do |state| %>
  49. <option value=<%= state.id %>><%= state.name %>
  50. <% end %>
  51.  
  52. </select>
  53. <% end %>
  54.  
  55. <div id="center_city_container">
  56. <%= render :partial => 'select_city'%></p>
  57. </div>
  58.  
  59. <%= observe_field("center_state_id",
  60. :frequency => 1,
  61. :update => "center_city_container",
  62. :url => {:controller => 'center', :action => 'filtered_city_select',:method=>'post'},
  63. :with => "'state_id=' + escape(value)",
  64. :on=> 'click')%>
  65.  
  66.  
  67. <br>
  68.  
  69.  
  70. ##_select_city.rhtml [partial]
  71.  
  72.  
  73. <br>
  74.  
  75. <% if @cities %>
  76. <label name=center[city_id]>City:</label>
  77. <select name="center[city_id]" id="center_city_id">
  78. <option value="">-- Select City --</option>
  79.  
  80. <% @cities.each do |city| %>
  81. <option value=<%= city.id %>><%= city.name %>
  82. <% end %>
  83.  
  84. </select>
  85. <% end %>
Add Comment
Please, Sign In to add comment