【问题标题】:Padrino app not loading custom helpers when deployed to tomcat windows 7部署到 tomcat windows 7 时,Padrino 应用程序未加载自定义帮助程序
【发布时间】:2014-10-30 01:32:45
【问题描述】:

我有一个在 linux 上使用 jruby 开发的 padrino 应用程序,它运行良好。但是,当我使用 warbler 将其部署到 Windows 7 上的 Tomcat 时,访问页面时出现以下错误:

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) }

这是 app/app.rb 中的违规行:

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

更新:我从来没有弄清楚为什么我不能让 tomcat 与我的应用程序一起工作,而且它没有被 padrino 社区的人复制。我搬到了解决问题的码头。

【问题讨论】:

    标签: tomcat jruby padrino warbler


    【解决方案1】:

    我建议你在控制器或相关模型文件中定义authenticate
    提供了一个Helper方法来渲染html,如果你想使用辅助方法,你应该先include HelperModule

    【讨论】:

    • include HelperModule 只会产生未初始化的常量错误。我在 app.rb 中有 register Padrino::Helpers
    【解决方案2】:

    我通过将 authenticate 调用放在 auth_helper.rb 文件中的帮助程序代码之后来消除此错误:

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

    现在我在 tomcat 中只得到 404,所以我不确定这是否真的有效。

    【讨论】:

      猜你喜欢
      • 2016-07-17
      • 2013-06-03
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      • 2011-04-24
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多