我正在重写 Devise 的 Devise::PasswordsController
,因此我可以将其用作 RESTful Web 服务。为此,我重写了所有四种方法(new
、create
、edit
和 update
),基于设计原创 Devise::PasswordsController
class 。除了 update
方法之外,其他都很简单,该方法使用名为 Devise.sign_in_after_reset_password
的设计属性。我发现它是在 library module 中定义的,但是当我尝试访问它时,出现以下错误:
NoMethodError in Api::V1::PasswordsController#update
undefined method `sign_in_after_reset_password' for Devise:Module
Extracted source (around line #37):
36 resource.unlock_access! if unlockable?(resource)
37 if Devise.sign_in_after_reset_password
38 flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
39 set_flash_message(:notice, flash_message) if is_flashing_format?
40 sign_in(resource_name, resource)
到目前为止,我尝试require 'devise'
,但没有成功。我用谷歌搜索了一段时间,但也没有找到任何东西。我对 ruby 和 ruby on Rails 有点陌生,所以我真的不知道该去哪里寻找。任何帮助将不胜感激。我使用 RoR 4.2.1
和 Ruby 2.2.1 (2015-02-26)
最佳答案
检查您使用的 devise gem 的版本。我想您使用的是最新发布的版本(此时为 3.4.1),但覆盖了 master 的代码。
正如您在这里看到的:https://github.com/plataformatec/devise/blob/v3.4.1/app/controllers/devise/passwords_controller.rb Devise::PasswordsController
在当前发布的版本中不使用 sign_in_after_reset_password
。
sign_in_after_reset_password
方法已由以下提交引入: https://github.com/plataformatec/devise/commit/f0992e4a96352dbb2dfec731f46a51f99a013b29
关于ruby-on-rails - Ruby on Rails 访问 Controller 中的 Devise.sign_in_after_reset_password,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30067524/