Rails: Devise: How can I edit user information?

EastsideDev picture EastsideDev · Jun 5, 2012 · Viewed 10.9k times · Source

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?

Answer

Jesse Wolgamott picture Jesse Wolgamott · Jun 5, 2012

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.