Rails: Devise: How can I edit user information?
Asked Answered
H

1

7

I have a Rails app set up using Devise, with a Registration controller.

What's working so far:

New user registration Login Logout Home About Confirmation Password reset

Not working is edit, as in I can't figure out the URL/REST call I should be making to get edit to show up. I do have a views/registrations/edit.html.erb page.

Following is the portion of my routes that's specific to Registration:

cancel_user_registration GET    /cancel(.:format)              registrations#cancel
       user_registration POST   /                              registrations#create
   new_user_registration GET    /request_invite(.:format)      registrations#new
  edit_user_registration GET    /edit(.:format)                registrations#edit

Following is the portion of my routes.rb that's specific to devise:

devise_for :users, :controllers => { :registrations => 'registrations', :confirmations => 'confirmations' }, :path => '', :path_names => { :sign_in => "login", :sign_up => "request_invite" }

I tried the following:

http://localhost:3000/edit  
http://localhost:3000/edit/:id
http://localhost:3000/registrations/:id/edit
http://localhost:3000/user/:id/edit

I get: No route matches [GET] ...

There are a couple of useful Q&A sessions on StackOverfloww, but I could not figure out how to make the advice here work for me. Any ideas?

Hoebart answered 5/6, 2012 at 15:57 Comment(0)
D
6

I typically just add a

resources :users, only: [:show, :edit, :update]

This will give you a /users/:id route (your profile), and can edit and update it. That way, you're interacting with the User model just as you normally would, outside of Devise.

Disclaim answered 5/6, 2012 at 16:3 Comment(6)
I added this to routes.rb, and restarted the rails server. Now I'm getting the following error: uninitialized constant UsersControllerHoebart
You will need to implement UsersControllerDisclaim
Wouldn't that conflict with my RegistrationsController? The registrations controller is handling new registrations.Hoebart
No. And as I wrote in the routes, you're only doing the show/edit/update.Disclaim
This seems to be working. I have some minor additional bugs. I moved show.html.erb, edit.html.erb and index.html.erb into views/users (as well as the corresponding methods from the RegistrationsController. The last thing I want to check after doing this is the destroy method (whether it belongs to the registrations controller or the users controller)Hoebart
You can add it wherever you want, but I'd probably control it myself in the UsersController.Disclaim

© 2022 - 2024 — McMap. All rights reserved.