如何编辑用户信息

如何编辑用户信息

本文介绍了Rails:设计:如何编辑用户信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Devise并带有注册控制器的Rails应用程序.

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

到目前为止,什么工作正常:

What's working so far:

新用户注册登录登出家关于确认密码重置

New user registrationLoginLogoutHomeAboutConfirmationPassword reset

编辑无效,因为我无法弄清楚应该显示的URL/REST调用.我确实有一个views/registrations/edit.html.erb页面.

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

以下是我的route.rb中专门设计的部分:

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" }

我尝试了以下操作:

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

我得到:没有路线与[GET]相匹配...

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

在StackOverfloww上有几个有用的问答环节,但是我不知道如何使这里的建议对我有用.有什么想法吗?

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?

推荐答案

我通常只添加一个

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

这将为您提供/users/:id路由(您的个人资料),并可以对其进行编辑和更新.这样,您就可以像平常一样在Devise之外与User模型进行交互.

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.

这篇关于Rails:设计:如何编辑用户信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:21