Rails 3 http_basic_authenticate_with only in production environment?

偶尔善良 提交于 2019-11-30 18:02:25

Yes, try:

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

Just add this to your example

http_basic_authenticate_with :name => 'user', :password => 'secret' if Rails.env.production?
authenticate_or_request_with_http_basic do |username, password|
  username == "user" && password == "secret"
end if Rails.env.production?
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!