Rails: Devise: How can I edit user information?

做~自己de王妃 提交于 2019-12-01 04:50:38

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10900664/rails-devise-how-can-i-edit-user-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!