2010-05-23 4 views
0

AuthLogic 예제 응용 프로그램과 거의 똑같이 AuthLogic을 설정했습니다 (http://github.com/binarylogic/authlogic_example).AuthLogic - 시스템 전체에서 현재 사용자 ID를 확인하는 방법은 무엇입니까?

사용자가 사용자로 로그인하면 사용자를 시스템으로 보내고 사용자 컨트롤러와 떨어져있는 링크를 클릭 할 수 있습니다. 이것은 엄청난 멍청한 질문이지만, 관련없는 뷰 또는 관련없는 컨트롤러와 같이 다른 곳의 사용자 ID 및 기타 속성에 어떻게 액세스 할 수 있습니까?

내가하고 싶은 것의 예 :

#matchings controller 
@matching = Matching.find_by_user_id(user.id) 

답변

5

당신은 사용할 수 있습니다 current_user 또는 @current_user. current_user를 리턴하는 함수는 응용 프로그램 제어기에 정의됩니다.

 
... 
    private 
    def current_user_session 
    return @current_user_session if defined?(@current_user_session) 
    @current_user_session = UserSession.find 
    end 

    def current_user 
    return @current_user if defined?(@current_user) 
    @current_user = current_user_session && current_user_session.record 
    end 
... 

그래서, 당신은 사용할 수 있습니다 @matching = Matching.find_by_user_id(current_user.id) 또는
@matching = Matching.find_by_user(current_user)

+0

감사를 많이 칼리을. 완전한! – sscirrus

관련 문제