无法覆盖Devise密码控制器 [英] Cannot override Devise passwords controller

查看:84
本文介绍了无法覆盖Devise密码控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提交电子邮件以向我发送重置密码说明后,我需要我的Rails应用程序重定向到主页。 Devise,默认情况下会在输入电子邮件后呈现登录表单。

I need my Rails app to redirect to the home page after I submit the email to send me reset password instructions. Devise, by default renders the sign in form after entering the email.

因此,我尝试覆盖 Devise :: PasswordsController 并更改其 redirect_to ,但没有成功。实际上,我认为Rails甚至都不会上课。这可能是一个非常愚蠢的错误,但我花了半天没有成功。

So I am trying to override the Devise::PasswordsController and change its redirect_to, but no success. In fact, I don't think Rails is even taking in my class. It could be a very stupid mistake but I have been at it for half a day with no success.

我接受了从此处

这是我的控制器:

class PasswordsController < Devise::PasswordsController
  protected
  def after_sending_reset_password_instructions_path_for(resource_name)
    root_url
  end
end

Routes.rb:

Routes.rb:

devise_for :users, :controllers => {:passwords => "passwords"}
devise_for :users, :controllers => {:registrations => "registrations"}
devise_for :users, :controllers => {:sessions => "sessions"}

我想提一下,我在同一个版本中重写了Devise的注册和会话控制器应用程序,它们似乎可以正常工作。

I would like to mention that I have overridden Devise's Registations and Sessions Controllers in the same app, and they seem to work fine.

推荐答案

应该可以使用最新版本的Devise(2.1 .2)。

It should be possible to override the controller with the latest version of Devise (2.1.2).

class PasswordsController < Devise::PasswordsController
  def new
    super
  end

  def create
    ..override method here..
  end
end

并在 config / routes.rb 中:

devise_for :users, controllers: { passwords: 'passwords', .. }

如果Rails使用派生的,则可以使用耙路进行检查。 PasswordsController 而不是原始密码,例如,路由应包含 passwords#new 而不是 devise / passwords#new

You can check with rake routes if Rails uses the derived PasswordsController instead of the original one, the routes should for instance contain passwords#new instead of devise/passwords#new.

这篇关于无法覆盖Devise密码控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆