Rails 3 http_basic_authenticate_with only in production environment?

Cojones picture Cojones · Jan 5, 2012 · Viewed 7.8k times · Source

is there a way to only use

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

when the server is running on production mode?

Answer

Tim Brandes picture Tim Brandes · Jan 5, 2012

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