如何在用户首次使用确认电子邮件 link 登录时设计 gem 转到特定页面,但仅在这种情况下

How to make devise gem go to specific page when user logs in for the FIRST time using confirmation email link but only in this situation

所以我正在尝试建立一个社交网络 rails 练习使用设计 gem 要求用户确认电子邮件以启用登录。

我的问题: 我希望用户在 he/she 首次登录时填写表格。这是第一次发生在他们点击确认电子邮件中的 link 时。

用户登录的所有其他时间都会转到不同的页面。

我该怎么做?

您可以通过重写设计确认方法来实现此功能 after_confirmation_path_for。

class ConfirmationsController < Devise::ConfirmationsController

  private

  def after_confirmation_path_for(resource_name, resource)
    your_new_after_confirmation_path
  end

end

在您的 routes.rb 中添加以下行,以便设计使用您的自定义控制器。

devise_for :users, controllers: { confirmations: 'confirmations' }

然后重启服务器。