Posted almost 4 years ago. Visible to the public.

Render a view from a model in Rails

This works, at least in Rails 3+:

Copy
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.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Author of this card:

Avatar
Henning Koch
Last edit:
almost 2 years 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