我只在应用程序处于生产模式时才试图使用skip_before_filter。 (我不希望公开我的开发实例,我希望应用程序自动检测它的实例类型,并在未处于生产模式时显示登录屏幕)。所以,我的应用程序控制器具有以下行:skip_before_filter忽略条件
before_filter :authenticate_user!, :except => "sign_in" #redirects to log-in
而控制器用于显示网页有这一行:
skip_before_filter :authenticate_user!, :only => :show, :if => :in_production
#public pages are public, but only when in production.
而且in_production很简单:
def in_production
ENV['RAILS_ENV']=='production'
end
我认识到,有可能是其他途径这里,但我很好奇,为什么skip_before_filter似乎忽视了条件和永远只是跳过的before_filter。有什么我失踪?
使用Rails 2.3.9和Devise身份验证gem。 – Smudge 2011-01-09 01:03:27