Skip to content

Instantly share code, notes, and snippets.

@kmamykin
Created June 28, 2011 08:26
Show Gist options
  • Save kmamykin/1050726 to your computer and use it in GitHub Desktop.
Save kmamykin/1050726 to your computer and use it in GitHub Desktop.
How to render Rails 3 view in a rake task
task :renderview => :environment do
app = YourApp::Application
app.routes.default_url_options = { :host => 'xxx.com' }
controller = YourController.new
view = ActionView::Base.new(app.config.paths.app.views.first, {}, controller)
view.class_eval do
include ApplicationHelper
include app.routes.url_helpers
end
puts view.render(:template => 'your/action')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment