# Render\_to\_string inside method shared across several controllers

**URL:** <https://www.ruby-forum.com/t/render-to-string-inside-method-shared-across-several-controllers/170855>\
**Category:** Rails\
**Created:** [June 23, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/render-to-string-inside-method-shared-across-several-controllers/170855 "2009-06-23T17:22:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![christer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a5b964/32.png) [@christer](https://www.ruby-forum.com/u/christer)\
**Post date:** [June 23, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/render-to-string-inside-method-shared-across-several-controllers/170855/1 "2009-06-23T17:22:23Z")

</div>

I use render\_to\_string to generate short reports (in HTML) under  
certain conditions when users access my application. The reports are  
stored in the database and uses database information at the time they  
are generated (and can thus not be generated later, e.g; when you want  
to consult them). The reports are generated the same way regardless of  
which controller has been accessed. Conditions for generating reports  
are tested in a before\_filter and the method that generates the  
reports and that calls render\_to\_string is in a helper. The  
render\_to\_string uses both a layout and a view template.

My problem: there is (as far as I can se) no way to specificy where  
the view template is stored. Instead, render\_to\_string assumes that it  
is stored in app/views/\<the\_controller\>, where \<the\_controller\> is the  
controller accessed. But I need this to work for several controllers!  
The only solution I have found is to store copies of the view template  
in all the app/views/ directories. Highly inelegant, and  
will lead to maintenance nightmares. Any suggestions? (Maybe I should  
put it all into the layout and just have empty view templates?)
