chr*_*mer 22

从我可以从文档中理解,http_basic_authenticate_with作为一个接受名称和密码的前过滤器,如

http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
Run Code Online (Sandbox Code Playgroud)

而authenticate_or_request_with_http_basic接受一个块,允许您插入一些代码以确定是否应对其进行身份验证(文档).例如

before_filter :authenticate

def authenticate
  authenticate_or_request_with_http_basic('Administration') do |username, password|
    ActiveSupport::SecurityUtils.secure_compare(username, "admin") &&
    ActiveSupport::SecurityUtils.secure_compare(password, "password")
  end
end
Run Code Online (Sandbox Code Playgroud)