在我提交电子邮件以向我发送重置密码说明后,我需要我的 Rails 应用程序重定向到主页。设计,默认情况下在输入电子邮件后呈现登录表单。
所以我试图覆盖 Devise::PasswordsController
并更改其 redirect_to
,但没有成功。事实上,我认为 Rails 甚至都没有上过我的课。这可能是一个非常愚蠢的错误,但我已经研究了半天,但没有成功。
我的想法是覆盖 here 中的密码 Controller .
这是我的 Controller :
class PasswordsController < Devise::PasswordsController
protected
def after_sending_reset_password_instructions_path_for(resource_name)
root_url
end
end
路线.rb:
devise_for :users, :controllers => {:passwords => "passwords"}
devise_for :users, :controllers => {:registrations => "registrations"}
devise_for :users, :controllers => {:sessions => "sessions"}
我想提一下,我已经在同一个应用程序中覆盖了 Devise 的注册和 session Controller ,它们似乎工作正常。
最佳答案
应该可以使用最新版本的 Devise (2.1.2) 覆盖 Controller 。
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
而不是原始的,您可以使用 rake routes
检查,例如路由应该包含 passwords#new
而不是 devise/passwords#new
。
关于ruby-on-rails - 无法覆盖设计密码 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8809681/