我有一个简单的导轨安装发电机发动机我做:我可以在生成器中运行耙子任务吗?
module Bouncer
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../../templates", __FILE__)
desc "Copies locale file and migrations to your application."
def copy_locale
copy_file "../../../config/locales/en.yml", "config/locales/bouncer.en.yml"
end
def copy_migrations
# I would like to run "rake bouncer_engine:install:migrations" right here
# rather than copy_file "../../../db/migrate/blah.rb", "db/migrate/blah.rb"
end
end
end
end
当用户运行rails g bouncer:install
,语言环境的文件复制到自己的应用程序。我也想复制我的迁移,但不是使用copy_file
方法,我希望我可以在发生器内运行rake bouncer_engine:install:migrations
,就像我从命令行执行的那样。我怎样才能做到这一点?
是的,我试图让它作为安装任务的一部分运行,我认为你不能只是在生成器内运行一个rake任务呢? – stephenmurdoch 2012-04-07 11:26:37
据我所知,不是直接通过重新使用您的代码。但是从你的代码运行rake命令作为shell命令应该可以工作......你只需要确保在正确的目录 – Vapire 2012-04-07 11:30:52
ahh中执行它,谢谢你的信息。我正在使用'Rake :: Task ['rake bouncer_engine:install:migrations'] .'执行'在我的生成器中,但现在我只是要做你所说的并使用[这种技术]复制文件http://www.dixis.com/?p=444) – stephenmurdoch 2012-04-07 12:50:46