gpt4 book ai didi

ruby-on-rails - 在 Devise 中使用自己的注册 Controller

转载 作者:数据小太阳 更新时间:2023-10-29 08:10:37 26 4
gpt4 key购买 nike

我使用 devise 进行身份验证。我想使用我自己的注册 Controller ,而不是内部设计使用的注册 Controller 。所以上去并按照此处提供的说明进行操作,https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password

从 Devise 复制 registrations_controller.rb 文件(记得从与您的 devise gem 相同的设计版本复制 Controller )
将其放入您的/app/controllers 目录。
在 config/routes.rb 添加 :controllers => { :registrations => "registrations"} 到你的 devise_for root。
确保将文件命名为 registrations_controller.rb
更改第一行:class Devise::RegistrationsController < ApplicationController to class RegistrationsController < ApplicationController

我使用的是 1.1 版本的设计,我从这里复制了 registrations_controller.rb 文件。 https://github.com/plataformatec/devise/blob/v1.1/app/controllers/devise/registrations_controller.rb

现在,当我点击注册 Controller 的新 Action 时,我收到以下错误

NoMethodError (undefined method `new_with_session' for User:Class):
app/controllers/registrations_controller.rb:71:in `build_resource'
app/controllers/registrations_controller.rb:8:in `new'

我的 registrations_controller.rb 看起来和我从那里复制的一模一样。可能是什么问题呢?谢谢。

最佳答案

你在这里的人身上看到了同样的问题:

http://groups.google.com/group/plataformatec-devise/browse_thread/thread/9733963d63a8a77a

使用 1.1.2 标签中的那个,它应该可以工作。这是假设它正在使用 Devise 的内置 Controller 并且模型加载了“可注册”模块。

关于ruby-on-rails - 在 Devise 中使用自己的注册 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5062436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com