나는 간단한 레일 내가 만들고있어 엔진을 위해 발전기를 설치 있습니다 제너레이터에서 레이크 작업을 실행할 수 있습니까?
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
을 실행할 수 있기를 바랬습니다. 명령 줄에서 수행하는 것처럼 말입니다. 어떻게해야합니까?
예, 설치 작업의 일부로 실행하려고합니다. 그러면 제네레이터 내부에서 레이크 작업을 실행할 수 없습니까? – stephenmurdoch
내가 아는 한 코드를 다시 사용하여 직접적으로 사용할 수 없습니다. 그러나 코드에서 셸 명령으로 rake 명령을 실행하면됩니다. 올바른 디렉토리에서 실행하도록하십시오. – Vapire
아, 감사합니다. 제 생성기 내부에서'Rake :: Task [ 'rake bouncer_engine : install : migrations']. execute'를 사용하려고했지만 이제는 당신이 말하는 것을하고 [이 기술]을 사용하여 파일을 복사하려고합니다. (http://www.dixis.com/?p=444) – stephenmurdoch