【问题标题】:Rails: Devise: How can I edit user information?Rails:设计:如何编辑用户信息?
【发布时间】:2012-06-05 15:57:54
【问题描述】:

我有一个使用 Devise 设置的带有注册控制器的 Rails 应用程序。

到目前为止的工作情况:

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

不工作是编辑,因为我无法弄清楚我应该进行的 URL/REST 调用以显示编辑。 我确实有一个views/registrations/edit.html.erb 页面。

以下是我的特定于注册的路线部分:

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

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

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] ...

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

【问题讨论】:

    标签: ruby-on-rails devise-confirmable


    【解决方案1】:

    我通常只是添加一个

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

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

    【讨论】:

    • 我将此添加到 routes.rb,并重新启动了 rails 服务器。现在我收到以下错误:未初始化的常量 UsersController
    • 你需要实现 UsersController
    • 这不会和我的 RegistrationsController 冲突吗?注册控制器正在处理新的注册。
    • 没有。正如我在路线中所写,您只是在进行显示/编辑/更新。
    • 这似乎有效。我有一些额外的小错误。我将 show.html.erb、edit.html.erb 和 index.html.erb 移动到视图/用户中(以及来自 RegistrationsController 的相应方法。这样做后我要检查的最后一件事是销毁方法(是否它属于注册控制器或用户控制器)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    • 2016-04-10
    相关资源
    最近更新 更多