« back to all cards in this deck
Posted 12 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.

Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

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