Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke rails migration generator programmatically?

Simply Running rails g from command line suffers from long time of pre-loading. I want to fast generate multiple migrations from a running rails c, so I tried:

require 'rails/generators'
Rails::Generators.invoke('migration',['user_book_list_followings'],{:behavior=>:invoke, :destination_root=>Rails.root})

You ask where did I get that :behavior and :destination_root arguments? Well, I pried at the Rails::Generators#invoke execution point when I run the generator from the command and recorded the exact arguments.

However, the funny thing was, I was presented with a error saying:

No value provided for required options '--orm'

Did I miss anything? (I was on Rails 3.2.3)

like image 714
Minqi Pan Avatar asked Nov 04 '22 23:11

Minqi Pan


1 Answers

require 'rails/generators'
Rails::Generators.invoke("active_record:migration", ["create_something", "list_order:string", "name:string"], {migration: true, timestamps: true})
like image 156
Marcel Mongs Avatar answered Nov 09 '22 09:11

Marcel Mongs