2014-09-05 2 views
1

리눅스에서 jruby를 사용하여 개발 한 패드 리노 앱이 있는데 제대로 작동합니다. 그러나 나는 솔새를 사용하여 Windows 7에서 톰캣에 배포 할 때, 페이지에 액세스 할 때 나는 다음과 같은 오류가 발생합니다 : 응용 프로그램/app.rb에서 잘못된 라인 여기바람둥이 창문에 배치했을 때 Padrino 앱이 사용자 정의 도우미를로드하지 않습니다.

undefined local variable or method `authenticate' for #<MyApp:0x480ebb> 
file: app.rb 

C:/Program Files (x86)/Apache Software Foundation/Tomcat 8.0/webapps/theapp/WEB-INF/app/app.rb in MyApp 
authenticate 
C:/Program Files (x86)/Apache Software Foundation/Tomcat 8.0/webapps/theapp/WEB-INF/gems/gems/padrino-core-0.12.2/lib/padrino-core/application/routing.rb in filter! 
    base.filters[type].each { |block| instance_eval(&block) } 

입니다 :

class MyApp < Padrino::Application 
    # lots of standard code 
    register Padrino::Helpers 

    before do 
    authenticate 
    end 
end 

가 그리고 이 도우미 파일은 app/helpers/auth_helper.rb입니다. (도우미는 원래 MyApp.helpers do으로 선언되었지만 모듈로 변경하려고 시도했지만 운이 없었습니다.)

class MyApp 
    module AuthHelper 

    def logged_in? 
     session[:user].present? 
    end 

    def authenticate 
     if !logged_in? 
     # Allow login page to be seen 
     allowed_urls = ['/','/login', '/account/activate', '/account/register'] 
     return if allowed_urls.include? request.path_info 
     end 

     if logged_in? 
     @user = session[:user] 
     else 
     redirect to('/login') 
     end 
    end 

    def logout 
     @user = nil 
     session.clear if logged_in? 
     redirect to('/login') 
    end 
    end 

    helpers AuthHelper 
end 

업데이트 : 나는 내 응용 프로그램과 함께 작동하도록 바람둥이 가져올 수 없습니다 이유 일한 적이 있으며이 대부가 지역 사회에서 사람이 복제되지 않았습니다. 나는 문제를 해결 한 부두로 이사했다.

답변

1

컨트롤러 또는 관련 모델 파일에 authenticate을 정의하는 것이 좋습니다.
메서드는 html 렌더링을 위해 제공되며, 도우미 메서드를 사용하려면 include HelperModule이 먼저 있어야합니다.

+0

'''HelperModule'''은 단지 초기화되지 않은 상수 오류를 생성합니다. app.rb에''Padrino :: Helpers'''를 등록해야합니다. – kristianp

0

나는 auth_helper.rb 파일에서 도우미 코드 뒤에 authenticate 전화를 넣어이 오류를 제거있어 :

class MyApp < Padrino::Application 

    # Pre/Post Filters 
    before do 
    authenticate 
    @breadcrumbs = [{label: 'Home', href: '/'}] 
    end 
end 

는 지금은 바람둥이 404 년대 아무것도 얻을 수 없다, 그래서 나는이있다 확실하지 않다 실제로 일했다.