【问题标题】:Name error:Uninitialised constant-Rails namespaced modules名称错误:未初始化的常量 Rails 命名空间模块
【发布时间】:2016-02-15 14:34:17
【问题描述】:

我有 Rails 应用程序,其中我已命名所有必需的模块。模块未加载并获取 Name error Uninitialised constant Udp

/app/adapters/Udp/     #Here Udp is the module name

包含两个文件。

first.rb

module Udp
  class First        #First is the class name
    def self.first_ac
        "first"
    end
  end
end

sec.rb

module Udp
  class Sec
    def self.sec_ac
        "sec"
    end
  end
end

config/application.rb

config.autoload_paths += Dir["#{config.root}/app/adapters/**/*"]

我正在尝试访问: Articles_controller

def index
  msg = Article.invite
  render text: msg
end

文章.rb

def self.invite
    msg = Udp::First.first_ac
    msg
end 

请帮我解决。

【问题讨论】:

  • 这不仅仅是因为你的文件夹是 Udb(注意末尾的 b)而你的模块是 Udp(注意末尾的 p)是吗?还是问题中的错字?
  • 对不起。这是一个打字错误。我现在已经编辑了。

标签: ruby-on-rails ruby uninitialized-constant


【解决方案1】:

我通过如下编辑/config/environments/development.rb解决了这个问题

config.eager_load = true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 2015-05-03
    • 2016-07-15
    • 1970-01-01
    相关资源
    最近更新 更多