ruby-on-rails - 如何在 Devise Rails 5 上更改 @resource 确认 URL?
问题描述
我需要更改此资源
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %> </p>
我不需要重定向到令牌路径,只需在用户确认电子邮件后重定向到 root_path
谢谢!
解决方案
Devise 有很多内置的功能。
为了改变它的行为,你必须隐式地覆盖它的行为或以某种方式修改它。
在这种情况下,您希望有一个从 devise conf contr 继承的 Confirmations 控制器。在里面你想
class ConfirmationsController < Devise::ConfirmationsController
# some other code if you want to change how certain views behave
private
def after_confirmation_path_for(resource)
sign_in(resource) # signs in the user at confirmation
# does whatever you want after the user is singed in at the confirmation
# - this is where you may want to redirect or whatever you desire
after_sign_in_path_for(resource)
end
end
在应用程序控制器中定义 after_sign_in_path_for
您可以执行以下操作:
def after_sign_in_path_for(resource)
root_path
end
这应该可以帮助您入门,请检查设计文档,因为它们非常可靠。
推荐阅读
- c - C 程序输出复杂度
- javascript - Webpack / React:内联加载程序在不被调用的情况下执行(具有动态导入的内联加载程序的意外行为)
- angular - Angular ReactiveForm 将 Form.Value 合并到对象
- selenium - 使用 gherkin 和 specflow 的 BDD 迭代
- php - addnote.php 问题连接到android studio
- javascript - 在 Node.js 中的类中启动并返回一个类
- javascript - 如何删除 Material React Modal 中的蓝色边框?
- python - 从 .loc 查询返回字符串
- hbase - HBase Zookeeper AUTH_FAILED - 找不到任何 Kerberos tgt
- node.js - Sequelize 在 belongsToMany 关联中获取未知列