« back to all cards in this deck
Posted 8 months 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', :locals => { :@users => @users } )

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

Hat tip to BitCrowd.

Author of this card:

Avatar
Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
Posted by Henning Koch to makandropedia