ruby NameError仅在AWS上未初始化的常量

时间:2017-03-09 23:05:31

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

所以我有这些代码

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]

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

1 个答案:

答案 0 :(得分:0)

尝试为您的Objs添加前缀::,如此...

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

class ObjController < ActionController::Base

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

end