【问题标题】:ruby NameError uninitialized constant only on AWSruby NameError 未初始化常量仅在 AWS
【发布时间】:2017-03-10 07:55:39
【问题描述】:

所以我有这些代码

require_relative '../classes/obj/objs.rb'

class ObjController < ActionController::Base

  def get_objs
    objs = Objs::get_objs
    render :json => objs
  end

end

在 objs.rb 中

module Objs

def Objs.get_objs
  objs = {
     1 => 2,
  }

  return objs 
end

end

在我的流浪环境中,代码运行良好,但是当我上传到我的 EC2 实例时,它最终会抱怨:

NameError in ObjController#get_objs
uninitialized constant ObjController::Objs

两个环境都使用 ruby​​ 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

关于如何解决此问题的任何想法?

【问题讨论】:

    标签: ruby-on-rails ruby amazon-web-services amazon-ec2


    【解决方案1】:

    尝试在您的Objs 前加上::,就像这样...

    require_relative '../classes/obj/objs.rb'
    
    class ObjController < ActionController::Base
    
      def get_objs
        objs = ::Objs::get_objs
        render :json => objs
      end
    
    end
    

    【讨论】:

    • 我觉得 require_relative 出于某种原因无法正常工作
    猜你喜欢
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    相关资源
    最近更新 更多