Ruby on rails 检查模型是否可确认

Ruby on rails 检查模型是否可确认,ruby-on-rails,devise,Ruby On Rails,Devise,我对Rails有点陌生,所以如果我完全错了,就告诉我:) 我在rails应用程序中使用Desive构建了两个模型,一个是可确认的,另一个不是 我想在用户主页或单独的页面上设置(资源)的注册路径后的,表明已发送确认电子邮件,具体取决于我的资源是否必须确认其注册 我可以检查数据模型中是否存在确认字段,但是否有更干净的方法,比如resource.confirmable? 是否有比在注册路径后覆盖更干净的方法根据模型是否可确认重定向到不同页面 谢谢您可以执行以下操作: resource.class.

我对Rails有点陌生,所以如果我完全错了,就告诉我:)

我在rails应用程序中使用Desive构建了两个模型,一个是可确认的,另一个不是

我想在用户主页或单独的页面上设置(资源)的注册路径后的
,表明已发送确认电子邮件,具体取决于我的资源是否必须确认其注册

  • 我可以检查数据模型中是否存在确认字段,但是否有更干净的方法,比如
    resource.confirmable?

  • 是否有比在注册路径后覆盖
    更干净的方法根据模型是否可确认重定向到不同页面


谢谢

您可以执行以下操作:

resource.class.devise_modules.include?(:confirmable)
def after_sign_up_path_for(resource)
  if resource.class.devise_modules.include?(:confirmable) 
    if resource.active_for_authentication?
      "path for confirmed user"
    else
      "path for waiting for confirmation"
    end
  else
    "path for non confirmable model"
  end
end

关于检查用户是否已经确认,您可以使用以下方法:

resource.class.devise_modules.include?(:confirmable)
def after_sign_up_path_for(resource)
  if resource.class.devise_modules.include?(:confirmable) 
    if resource.active_for_authentication?
      "path for confirmed user"
    else
      "path for waiting for confirmation"
    end
  else
    "path for non confirmable model"
  end
end

查看文档:

看起来很合适,谢谢!在将其标记为已解决之前,我将等待几个小时,以便我可以回答“在注册后覆盖路径方法是否很好”。@Logar添加了一些更多信息,以备您需要。很好,我想我有我的答案了!