Welcome to the Treehouse Community
Looking to learn something new?
Admin editing other user details - Rails 4.1 + latest Devise + latest Simple Form
Hi everyone, I am writing my first Ruby project and I've dived right in the deep end, so apologies if my lack of deep Rails understanding is showing through.
I am trying to create a user management system, so admins can edit the details of users in the system without being logged in as them. I understand Devise does not have such functionality built in and that's what I'm trying to hack together myself.
I am nearly there. I have a 'Manage Users' page that successfully lists users in the system along with an 'Edit User' link next to each one:
<h2>Manage Users</h2> <p>As an administrator, you can add new users to the system. You can also edit or delete existing ones.</p> <p> <% @users = User.all %> <ul class="users"> <% @users.each do |user| %> <li><%= user.id %> <%= user.first_name %> <%= user.second_name %> <%= user.email %> <%= link_to "Edit User", edit_user_details_path(id: user.id) %></li> <% end %> </ul> </p>
Clicking on 'Edit User' correctly renders an 'Edit User Details' page according to the user selected (using id to identify):
<h2>Edit user details</h2> <p> <%= @user.first_name %> <%= @user.second_name %> <%= @user.email %> </p>
I now want to implement a form (using simple form) on the page shown above that allows the admin to make changes to the user's first name, second name, email, and an option to reset password. It should ideally behave like Devise's built in 'edit registrations' page but change a user who is not currently linked in. I'm completely stumped as to how I will achieve this. Any help appreciated.
Here is my Admin controller file for context:
class AdminController < ApplicationController def manage_users end def edit_user_details @user = User.find(params[:id]) end end
This is a complex as I am not as seasoned of a rails dev as some of our patrons at treehouse. Have you looked for any helper methods in the rails API that could help you solve your challenge. I also suggest getting better understanding of the rails architecture before diving to the deep end. the MVC pattern etc..
Hi Andrew, Thanks for your help, it is a difficult problem. In the end I uninstalled Devise and wrote my own user model from scratch since augmenting Devise and a separate user model to handle CRUD actions was proving too complicated at this stage.
No problem Chris!
All those rails generators can really confuse new rails developers like ourselves haha. Good luck with your project!