2012-07-19 2 views
1

응용 프로그램 컨트롤러 내에서 작업 세션 컨트롤러 작성 작업을 덮어 쓸 수있는 방법이 있는지 알고 싶습니다. 그래서 나는이 코드devise sessions 컨트롤러 작성 작업을 덮어 쓸 수있는 방법이 있습니까?

def check_concurrent_session 
    if is_already_logged_in? 
     flash[:error] = "We're sorry, you can't login to two places concurrently." 
     sign_out_and_redirect(current_user) 
    end 
    end 

을하고 난

그래서 내가 응용 프로그램 컨트롤러에 before_filter을 가지고 있습니다 .. 유증 세션 컨트롤러에서 조치를 생성 한 후 다른 사이트 어디에서나 실행이 필요하지만, 내가 할 수있는 분명히

before_filter :check_concurrent_session, :except => ["somecontoller"] 

이 잘못 같은 콘트롤을 제외하지만 당신은 아이디어를 얻을. 나는 내 자신의 세션 컨트롤러를 만들고 유증에서 상속 할 수 있습니다 알고 있지만이

답변

1
before_filter :check_concurrent_session 

def check_concurrent_session 
    return if controller_name == 'some_controller' 
    if is_already_logged_in? 
    flash[:error] = "We're sorry, you can't login to two places concurrently." 
    sign_out_and_redirect(current_user) 
    end 
end 
+0

에서 응용 프로그램 컨트롤러 내에서이 작업을 할 수있는 경우에는 내가 알고 싶어 .... 그래서 간단하게 .. 그 생각을 못했을 까봐 ... 감사합니다. – Trace

1

내가 필요 정확히이었다 application.rb

module XXX 
    class Application < Rails::Application 
    ... 

    config.to_prepare do 
     Devise::SessionsController.skip_before_filter :check_concurrent_session 
    end 
    end 
end 
+0

감사합니다. application.rb에서 다시 덮어 쓸 수 있다는 것을 알고 있습니다. 다시 한번 감사드립니다. – Trace

관련 문제