2010-06-07 5 views

답변

0

ApplicationController에서 before_filter을 사용하면 비슷한 결과를 얻을 수 있습니다. 이 작업은 모든 컨트롤러 작업에만 인증을 추가하는 것이므로 스타일 시트, 자바 스크립트 및 이미지와 같은 공용 디렉토리의 하위 디렉토리는 보호하지 않습니다. 어떤 이유로 그것이 당신이 찾고있는 것이라면 아마도 htpasswd 메소드를 사용해야 할 것입니다.

Railscasts : http://railscasts.com/episodes/82-http-basic-authentication - 모든 컨트롤러를 보호하려면 ApplicationController에 before_filterauthenticate을 넣기 만하면됩니다.

+0

스타일 시트와 같은 다른 공공 파일을 보호 할 수있는 방법이 있나요? – DDDD

0

기본 인증 단지 예를 들어 생산에서 다음 application_controller.rb에서

:

USERNAME = 'foo' 
PASSWORD = 'bar 

if RAILS_ENV['production'] 
before_filter :authenticate 
end 

개인

def authenticate 
    authenticate_or_request_with_http_basic do |user_name, password| 
     user_name == USERNAME && password == PASSWORD 
    end 
end