I'm trying to create a Rails form that allows an admin user to change the assigned roles of other users. The form I've created registers changes to the user (such as password or login changes), but doesn't register changes to the user's role, which is a separate model.
I'm using Acl9 for role-based authentication, which uses a User model, a Role model, and a Roles_user model which links the two.
Here's the code I have in my form:
<h1>Edit User</h1>
<% form_for(@user) do |form| %>
<%= error_messages_for :user %>
Login: <%= form.text_field :login %><br />
Password: <%= form.password_field :password %><br />
Password Confirmation: <%= form.password_field :password_confirmation %><br />
<% if current_user && current_user.has_role?(:admin) %>
<%= error_messages_for :roles %>
<% fields_for :roles do |role| %>
<%=
@roles = Role.find(:all, :order => "name").map {|u| [u.name, u.id] }
role.select(:id, @roles )
%>
<% end %>
<% end %>
<%= form.submit "Update" %>
<% end %>
<br />
<%= link_to "My Profile", account_path %>
<%= link_to "Logout", user_session_path, :method => :delete, :confirm => "Are you sure you want to logout?" %>
I don't get any errors when loading the page, but the selected role doesn't get associated to the user. Any help would be appreciated. Thanks!