简体   繁体   English

before_filter:except似乎不起作用

[英]before_filter :except doesn't seem to be working

I must be doing something silly. 我一定在做傻事。 Any ideas on why this wouldn't be working. 关于为什么这样不起作用的任何想法。 I get prompted to authenticate when making a request to the controller with the below config: 使用以下配置向控制器发出请求时,系统会提示我进行身份验证:

class ApplicationController < ActionController::Base

before_filter :auth, :except => [:aboutus]

The auth method is just this. auth方法就是这样。 It works fine but applies to all controllers including aboutus 它工作正常,但适用于所有控制器,包括aboutus

  #Simple HTTP Auth during development
  def auth
    authenticate_or_request_with_http_basic do |username, password|
      username == "REDACTED" && password == "REDACTED"
    end
  end 

Thanks 谢谢

This configuration would apply to the "aboutus" action of ApplicationController. 此配置将应用于ApplicationController的“ aboutus”操作。 Have you tried putting the before_filter definition in the controller that actually has the "aboutus" method/action? 您是否尝试过将before_filter定义放入实际上具有“ aboutus”方法/动作的控制器中?

You can put this in ApplicationController: 您可以将其放在ApplicationController中:

before_filter :auth

then, in the controller containing the aboutus method: 然后,在包含aboutus方法的控制器中:

skip_before_filter :auth, :only => :aboutus

this way you don't repeat code and everything looks nice. 这样,您就无需重复代码,一切看起来都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM