Rigel Group

They shoot Yaks, don't they?

Render Rails3 Views Outside of Your Controllers

If you ever had the need to break out of the MVC box and render a view template outside of your controller, the old-style Rails2 version went something like this:

1
body = ActionView::Base.new(Rails::Configuration.new.view_path).render(:file => "/orders/receipt.html.erb",:layout => false,:locals=>{:order=>order})

In Rails3, the same thing can be accomplished with this incantation:

1
2
3
4
av = ActionView::Base.new()
av.view_paths = ActionController::Base.view_paths
av.extend ApplicationHelper #or any other helpers your template may need
body = av.render(:template => "orders/receipt.html.erb",:locals => {:order => order})