我正在构建一个 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
环境规格:
- 红宝石 1.9.2
- 导轨 3.2.8