christer
2009-Jun-23 14:08 UTC
render_to_string inside method shared across several controllers
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/<controller> 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?)
Apparently Analagous Threads
- Re: Train wreck getting render_to_string to work from foreign controller [SOLVED]
- render_to_string() in a controller that isn''t default route?
- rendering a partial inside another using render_to_string and (:formats) in controller
- Using render_to_string in other custom classes
- Missing Template Error on render_to_string - Rails 3.2.2