Minqi Pan
Minqi Pan

Reputation: 2811

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)

Upvotes: 6

Views: 874

Answers (2)

nlta
nlta

Reputation: 1914

One solution to speed up callings rails g, is using spring.

Spring is a Rails application preloader. It speeds up development by keeping your application running in the background so you don't need to boot it every time you run a test, rake task or migration.

Upvotes: 0

Marcel Mongs
Marcel Mongs

Reputation: 21

require 'rails/generators'
Rails::Generators.invoke("active_record:migration", ["create_something", "list_order:string", "name:string"], {migration: true, timestamps: true})

Upvotes: 2

Related Questions