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?

Abe Petrillo
  • 2,368
  • 23
  • 34
EastsideDev
  • 6,257
  • 9
  • 59
  • 116

1 Answers1

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.

Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • I added this to routes.rb, and restarted the rails server. Now I'm getting the following error: uninitialized constant UsersController – EastsideDev Jun 05 '12 at 17:07
  • You will need to implement UsersController – Jesse Wolgamott Jun 05 '12 at 17:49
  • Wouldn't that conflict with my RegistrationsController? The registrations controller is handling new registrations. – EastsideDev Jun 05 '12 at 20:24
  • No. And as I wrote in the routes, you're only doing the show/edit/update. – Jesse Wolgamott Jun 05 '12 at 21:34
  • 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) – EastsideDev Jun 05 '12 at 22:55
  • You can add it wherever you want, but I'd probably control it myself in the UsersController. – Jesse Wolgamott Jun 05 '12 at 23:10