NameError: uninitialized constant GemName::Rails::Railtie

NameError: uninitialized constant GemName::Rails::Railtie

我正在创建一个 gem 来封装应用程序的一大块功能。他们 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)>'

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

知道我为什么会收到此错误吗?

错误在 class 定义的语法中。如下更新代码将允许 rake 任务 运行.

class Railtie < Rails::Railtie

class Railtie < ::Rails::Railtie