1

我为我的引擎编写了一些自定义生成器来简化我的工作。我想在我的引擎中直接生成一些文件。然而,生成器只能从虚拟应用程序访问,而不是直接从引擎访问。

my_engine_root:# rails g custom_generator  
Could not find generator custom_generator.

engine_dummy_path:# rails g custom_generator  
Everything works...

我试图要求生成器路径,但没有任何效果。我究竟做错了什么?

4

1 回答 1

0

First of all, isolate your custom generator to a separated engine, so you can add this excerpt to "script/rails" or "bin/rails", depending on rails version, in the engine which you want the generators available:

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])

then add rails, your custom generator gem and all dependencies to the Gemfile of your engine

gem 'rails', '~> 4.0.2'
gem 'my_custom_generator', :path => "/path/to/my_custom_generator"
于 2014-02-18T20:31:18.060 回答