[英]NameError: uninitialized constant GemName::Rails::Railtie
I'm creating a gem to encapslate a chunk of functionality from an application. 我正在创建一个gem,以封装来自应用程序的功能块。 Them gem essentially runs a rake task, but when I run the task with
bundle exec rake:assets:precompile
, I get the following error 他们gem实际上运行了rake任务,但是当我使用
bundle exec rake:assets:precompile
运行任务时,出现以下错误
rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'gem-name'.
/Users/tonyedwardspz/myprojects/westcornwallevents/config/application.rb:8:in `<top (required)>'
/Users/tonyedwardspz/myprojects/westcornwallevents/Rakefile:4:in `require'
/Users/tonyedwardspz/myprojects/westcornwallevents/Rakefile:4:in `<top (required)>'
NameError: uninitialized constant GemName::Rails::Railtie
/Users/tonyedwardspz/myprojects/westcornwallevents/config/application.rb:8:in `<top (required)>'
/Users/tonyedwardspz/myprojects/westcornwallevents/Rakefile:4:in `require'
/Users/tonyedwardspz/myprojects/westcornwallevents/Rakefile:4:in `<top (required)>'
The code for the module related to railtie is: 与railtie相关的模块的代码是:
require 'rails'
module GemName
module Rails
class Railtie < Rails::Railtie
railtie_name :gem_name
rake_tasks do
load "tasks/gem_name.rake"
end
end
end
end
Any ideas why I'm getting this error? 有任何想法为什么我会收到此错误吗?
The error is in the syntax of the class definition. 错误出在类定义的语法中。 Updating the code as following will allow the rake task to run.
如下更新代码将允许rake任务运行。
class Railtie < Rails::Railtie
to 至
class Railtie < ::Rails::Railtie
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.