I'm trying to make a page that updates my users' roles. I have a users controller and a method/action in the controller called "admin". All the admin definition does is store all the users in @users. In routes, the resource is users, and it has a collection do that gets :admin.
I'm updating the roles by creating a new form for each user and I have a save button for each form next to each user.
<table>
<tr>
<th>Username</th>
<th>Role</th>
<th>Update</th>
</tr>
<% @users.each do |user| %>
<%= form_for [user], :user => { :action => "update" } do |f| %>
<tr>
<td><%= user.username %></td>
<td><%= select("user", "role", options_for_select(['member', 'moderator','admin'], user.role) )%></td>
<td><%= f.submit %> </td>
</tr>
<% end %>
<% end %>
</table>
This works and updates, but it's not very intuitive. I would like to either have the submit button after the whole thing, or an ajax call that updates the role on change so the user doesn't have to worry about clicking 'save' at all.
Is there a way to avoid the double nested loop, and possibly add an ajax where the update button isn't necessary?
Thanks for any advice or help.