Posted almost 3 years ago. Visible to the public.

Render a view from a model in Rails

This works, at least in Rails 3+:

ApplicationController.new.render_to_string( :template => 'users/index', :layout => 'my_layout', :locals => { :@users => @users } )

Mind the weird syntax to set @ variables in :locals.

Hat tip to BitCrowd.

A bunch of books about building and maintaining large-scale Rails applications, all at a discounted price. Featuring best-selling books like Trailblazer, Fearless Refactoring, or Growing Rails Applications in Practice!

Author of this card:

Avatar
Henning Koch
Last edit:
12 months ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandropedia