制作引擎:未找到Lib类:未初始化的常量(NameError)

时间:2012-09-14 18:06:35

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2

我正在构建一个gem并创建:

“/ LIB / gem_name / resource.rb”

module GemName
  class Resource
    def initialize
      # nothing
    end
  end
end

和“/lib/gem_name.rb”

require "gem_name/engine"

module GemName
  def new_resource
    @resources << GemName::Resource.new
  end
end

在“/test/dummy/config/initializers/gem_name.rb”

GemName.new_resource

当我启动控制台时,显示以下消息:

unitialized constant GemName::Resource (NameError)

我检查gem_name.gemspec,其内容是:

$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "gem_name/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
  s.name        = "gem_name"
  s.version     = GemName::VERSION
  s.authors     = ["TODO: Your name"]
  s.email       = ["TODO: Your email"]
  s.homepage    = "TODO"
  s.summary     = "TODO: Summary of GemName."
  s.description = "TODO: Description of GemName."

  s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
  s.test_files = Dir["test/**/*"]

  s.add_dependency "rails", "~> 3.2.8"
  # s.add_dependency "jquery-rails"

  s.add_development_dependency "sqlite3"
end

环境规范:

  • ruby​​ 1.9.2
  • rails 3.2.8

1 个答案:

答案 0 :(得分:0)

也许您需要直接在“/lib/gem_name.rb”文件中要求gem_name/resource