Ça dépend de ton code…
#users_controller
def update_municipals
state = State.find(params[:name])
@municipals = state.municipals
a = 0
render :update do |page|
page.replace_html 'municipalfd', :partial => 'cantcoll', :object
=> @municipals
end
end
#new.html.erb (tjr pour users)
<%= error_messages_for :user %>
<% form_for :user, :url => users_path do |f| -%>
Login
<%= f.text_field :login %>
Email
<%= f.text_field :email %>
Password
<%= f.password_field :password %>
Confirm Password
<%= f.password_field :password_confirmation %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :surname %>
<%= f.text_field :surname %>
<%= f.label :birthday %>
<%= f.date_select :birthday, :start_year => 1900, :end_year =>
2100%>
<%= f.label :state %>
<%= f.select(:state_id, State.find(:all).map {|c| [c.name,
c.id]},{:prompt => "Select a state"}, {:onchange =>
"#{remote_function(:url => {:action => "update_municipals"},
:with =>
"'name='+value")}"}) %>
<%= render :partial => 'cantcoll', :object =>
@municipals %>
Select the role of the user:
<%= f.select(:role, %w{ voter admin}) %>
<%= f.label :has_voted %>
<%= f.check_box :has_voted %>
<%= submit_tag ‘Sign up’ %>
<% end -%>
#_cantcoll.html.erb
<% if @municipals == nil %>
<%= select(nil,:municipal, “select a canton first”) %>
<% else %>
<%= collection_select(:user,:municipal, @municipals, :municipal_name,
:municipal_name) %>
<% end %>