Skip to content

Instantly share code, notes, and snippets.

@cmaujean
Created November 9, 2010 22:49
Show Gist options
  • Save cmaujean/669992 to your computer and use it in GitHub Desktop.
Save cmaujean/669992 to your computer and use it in GitHub Desktop.
running a generator programatically
# Must be run in the context of your rails app
# if you put this in a rake task, you'll need to ensure the task depends on the :environment task
require 'rails/generators'
require "#{::Rails.root.to_s}/lib/generators/foo_bar/article/article_generator.rb"
# make a generator (new calls .shift on the first arg, so it must be looking for an array)
gen = FooBar::ArticleGenerator.new(["Der title of der article"])
# run your create_ methods here:
gen.create_article
gen.create_article_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment