Rails 3 http_basic_authenticate_with only in production environment?

我的未来我决定 提交于 2019-11-30 01:05:53

问题


is there a way to only use

http_basic_authenticate_with :name => 'user', :password => 'secret'

when the server is running on production mode?


回答1:


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



回答2:


Just add this to your example

http_basic_authenticate_with :name => 'user', :password => 'secret' if Rails.env.production?



回答3:


authenticate_or_request_with_http_basic do |username, password|
  username == "user" && password == "secret"
end if Rails.env.production?


来源:https://stackoverflow.com/questions/8741398/rails-3-http-basic-authenticate-with-only-in-production-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!