问题如下:
# 1) Create full engine `myengine` with Rails 4.2.10
rails _4.2.10_ plugin new myengine --full
# 2) Try to rails generate
$ bin/rails g
/usr/local/lib/ruby/gems/2.6.0/gems/railties-4.2.10/lib/rails/engine/commands.rb:17:in `<top (required)>':
undefined method `railtie_namespace' for nil:NilClass (NoMethodError)
当您符号链接引擎目录并通过链接通过以下方式到达那里时,会发生此问题:
cd path/to/somewhere
rails _4.2.10_ plugin new myengine --full
ln -s path/to/somewhere/myengine ~/favorite/myengine
cd ~/favorite/myengine
./bin/rails g
如果这样做,则会遇到错误。要解决此问题,请按如下所示更改bin/rails
顶部的几行:
# from
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/myengine/engine', __FILE__)
# to
require 'pathname'
ENGINE_ROOT = Pathname.new(__FILE__).realpath + '../..'
ENGINE_PATH = ENGINE_ROOT + 'lib/myengine/engine'
请参阅::Rails::Engine.find
的实现以了解该补丁为何起作用。