adding a migration with a generator
I have a gem that needs to add a migration I've tried using invoke "migration" but that see开发者_开发知识库med to ignore the arguments I was passing and used the ones passed to my generator.
What is the proper way to add a migration with a generator? I will need to pass a dynamic name to the migration e.g. create_#{first_arg}.
I'd suggest using a template for your migration instead of generating a new one: you can simply have your template, replace dynamic elements, and copy the template instance to the filesystem (prepending the migration's name with the time). That way, there's no need to generate an actual migration.
(If this is want you want to do, you might want to check out a post I wrote on a similar topic: http://davidsulc.com/blog/2011/05/22/adding-a-namespaced-rails-generator-to-a-standalone-ruby-gem/)
If you're set on running the migration command, you might want to try with Thor's run_ruby_script (http://rdoc.info/github/wycats/thor/master/Thor/Actions#run_ruby_script-instance_method) Note: Thor is the engine used for generators, as detailed in http://guides.rubyonrails.org/generators.html
精彩评论