Skip to content

Instantly share code, notes, and snippets.

@ryanstout
Created February 14, 2010 04:03
Show Gist options
  • Save ryanstout/303825 to your computer and use it in GitHub Desktop.
Save ryanstout/303825 to your computer and use it in GitHub Desktop.
# How to run a generator from a plugin's install.rb
begin
# First have to load up rails
unless Kernel.const_defined?('RAILS_ROOT')
Kernel.const_set('RAILS_ROOT', File.join(File.dirname(__FILE__), '..', '..', '..'))
end
if (File.exists?(RAILS_ROOT) && File.exists?(File.join(RAILS_ROOT, 'app')))
require "#{RAILS_ROOT}/config/boot"
require "#{RAILS_ROOT}/config/environment"
require 'rails_generator'
require 'rails_generator/scripts/generate'
end
# Run the generator
Rails::Generator::Scripts::Generate.new.run(['generator_name'])
rescue Exception => e
puts "The following error ocurred: " + e.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment