问题描述
我在Rails中使用Devise身份验证gem.
I'm using Devise authentication gem with Rails.
如何显示来自devise.en.yml的消息:
How to display the message from devise.en.yml:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes'
在发送了密码恢复电子邮件之后,而不是将其重定向到网站的根目录吗?
after password recovery e-mail has been sent, instead of being redirected to site's root?
更新:
我在devise_controller.rb中找到了一段有趣的代码:
I've found an interesting piece of code in devise_controller.rb:
def successfully_sent?(resource)
notice = if Devise.paranoid
resource.errors.clear
:send_paranoid_instructions
elsif resource.errors.empty?
:send_instructions
end
if notice
set_flash_message :notice, notice if is_navigational_format?
true
end
end
设置断点表明正在调用正确的行,已将:send_instructions 分配给通知,但调用了set_flash_message,但是我看不到所有结果,因为我立即被重定向到根路径.
Setting breakpoints shows that the right lines are being called, :send_instructions is assigned to notice , set_flash_message is called, but I cannot see the result of all this because I am immediately redirected to root path.
推荐答案
查看devise的PasswordsController的源代码:https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb#L42
Look at the source code for devise's PasswordsController: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb#L42
您必须在应用程序中创建一个从Devise :: PasswordsController继承的PasswordsController,仅实现after_sending_reset_password_instructions_path_for(resource_name)方法,并在设置路由时告知devise使用您的控制器
You'll have to create a PasswordsController in your app that inherits from Devise::PasswordsController, implement only the after_sending_reset_password_instructions_path_for(resource_name) method and when setting the routes tell devise to use your controller
class PasswordsController < Devise::PasswordsController
protected
def after_sending_reset_password_instructions_path_for(resource_name)
#return your path
end
end
在航线上
devise_for :users, :controllers => { :passwords => "passwords" }
这篇关于设备身份验证-密码恢复后无确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!