小编Smu*_*dge的帖子

skip_before_filter忽略条件

我只是在应用程序处于生产模式时才尝试使用skip_before_filter.(我不希望我的开发实例公开,我希望应用程序自动检测它所在的实例类型,并在它不处于生产模式时显示登录屏幕).所以,我的应用程序控制器有以下几行:

before_filter :authenticate_user!, :except => "sign_in" #redirects to log-in
Run Code Online (Sandbox Code Playgroud)

并且用于显示页面的控制器具有以下行:

skip_before_filter :authenticate_user!, :only => :show, :if => :in_production
#public pages are public, but only when in production.
Run Code Online (Sandbox Code Playgroud)

而in_production就是:

  def in_production
    ENV['RAILS_ENV']=='production'
  end
Run Code Online (Sandbox Code Playgroud)

我意识到这里可能还有其他途径,但我很好奇为什么skip_before_filter似乎忽略了条件并总是跳过before_filter.有什么我想念的吗?

ruby-on-rails devise

14
推荐指数
3
解决办法
1万
查看次数

标签 统计

devise ×1

ruby-on-rails ×1