Rigel Group Software Engineering

22Sep/11Off

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:

 
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:

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})
Filed under: Blog Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.