Search code examples
ruby-on-railsrubyruby-on-rails-4programmatically-created

How to create Rails project programmatically?


I'm using Rails 4.0.0.

I am aware of the commands rails new ... used to create a Rails project via terminal. Are there methods to do this programmatically?

I want to avoid having code invoke a pop-up terminal as not all users may have Linux.

Possible Solution

Programmatially copy existing base Rails project. Write to new directory.


Solution

  • You can use the same generator the command rails new uses, for example:

    require 'rails/generators/rails/app/app_generator'
    Rails::Generators::AppGenerator.start ['bar', '--skip-bundle']
    
    # Output:
    # create  
    # create  README.rdoc
    # create  Rakefile
    # create  config.ru
    # create  .gitignore
    # ...