简体   繁体   中英

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. It works fine but applies to all controllers including 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. Have you tried putting the before_filter definition in the controller that actually has the "aboutus" method/action?

You can put this in ApplicationController:

before_filter :auth

then, in the controller containing the aboutus method:

skip_before_filter :auth, :only => :aboutus

this way you don't repeat code and everything looks nice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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