Coj*_*nes 15 ruby-on-rails basic-authentication ruby-on-rails-3
有没有办法只使用
http_basic_authenticate_with :name => 'user', :password => 'secret'
Run Code Online (Sandbox Code Playgroud)
当服务器在生产模式下运行时?
小智 33
是的,试试:
class ApplicationController < ActionController::Base
before_filter :authenticate
def authenticate
if Rails.env.production?
authenticate_or_request_with_http_basic do |username, password|
username == "user" && password == "%$§$§"
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
bok*_*kor 13
只需将此添加到您的示例中
http_basic_authenticate_with :name => 'user', :password => 'secret' if Rails.env.production?
Run Code Online (Sandbox Code Playgroud)
authenticate_or_request_with_http_basic do |username, password|
username == "user" && password == "secret"
end if Rails.env.production?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7569 次 |
| 最近记录: |