【问题标题】:authenticate_user! for all but a single page -- how to do that easily?验证用户!除了一个页面之外的所有页面 - 如何轻松做到这一点?
【发布时间】:2017-01-11 13:26:25
【问题描述】:

我想在我的 Rails 应用程序中使用authenticate_user!,但只有一个页面“登录”页面。为此,我可以在所有控制器中插入authenticate_user!。但是将其插入ApplicationController 和 仅在“登录”页面上禁用,或者在 SessionController 中禁用“登录”操作。有可能吗?

【问题讨论】:

标签: ruby-on-rails ruby devise ruby-on-rails-5


【解决方案1】:

是的,你可以做到。,

class ApplicationController
  before_filter :authenticate_user!
end

class SessionsController < ApplicationController
  skip_before_filter :authenticate_user!
end

您可以使用except: 提及您要排除的方法。

【讨论】:

猜你喜欢
  • 2015-06-20
  • 1970-01-01
  • 2016-06-07
  • 1970-01-01
  • 1970-01-01
  • 2015-12-23
  • 2021-06-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多