# Using Rails view templates without the Controller? How?

**URL:** <https://www.ruby-forum.com/t/using-rails-view-templates-without-the-controller-how/148378>\
**Category:** Rails\
**Created:** [September 12, 2008, 11:12am UTC](https://www.ruby-forum.com/t/using-rails-view-templates-without-the-controller-how/148378 "2008-09-12T11:12:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [September 12, 2008, 11:12am UTC](https://www.ruby-forum.com/t/using-rails-view-templates-without-the-controller-how/148378/1 "2008-09-12T11:12:33Z")

</div>

Hi

I have a SupplierBreakdownReport class that uses a rails view to  
generate a html report, which then is converted into a PDF, as follows :

class ReportGeneratorController \< ApplicationController

…

def supplier\_breakdown\_report  
…  
if request.post?  
@report =  
SupplierBreakdownReport.new(@start\_date,@end\_date,params[:retailer\_trivial\_matrices])  
html = render\_to\_string :action=\>“supplier\_breakdown\_report”  
pdf = generate\_pdf(html)  
…  
end  
end

…

end

I now want to detach this report generation from the the Rails  
controller so that I can generate these report in the background (maybe  
using BackgroundDRB) without having to go through the rails controller.

I first though about using just ERB but this won’t suffice as custom  
rails methods like “render :partial=\>…” wont work with ERB. I need  
the full power of the rails templating system without going through the  
controller.

Does anyone have any ideas how to do this? Any help is appreciated.

Thanks  
Chris

---

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [September 13, 2008, 7:12pm UTC](https://www.ruby-forum.com/t/using-rails-view-templates-without-the-controller-how/148378/2 "2008-09-13T19:12:35Z")

</div>

On Sep 12, 5:12 pm, Chris R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> …
> 
> Does anyone have any ideas how to do this? Any help is appreciated.
> 
> ## Thanks Chris
> 
> Posted viahttp://www.ruby-forum.com/.

Cells _might_ work: [http://cells.rubyforge.org/](http://cells.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [September 14, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/using-rails-view-templates-without-the-controller-how/148378/3 "2008-09-14T22:33:04Z")

</div>

Chris R. wrote:

> Hi
> 
> I have a SupplierBreakdownReport class that uses a rails view to  
> generate a html report, which then is converted into a PDF, as follows :
> 
> class ReportGeneratorController \< ApplicationController
> 
> …
> 
> def supplier\_breakdown\_report  
> …  
> if request.post?  
> @report =  
> SupplierBreakdownReport.new(@start\_date,@end\_date,params[:retailer\_trivial\_matrices])  
> html = render\_to\_string :action=\>“supplier\_breakdown\_report”  
> pdf = generate\_pdf(html)  
> …  
> end  
> end
> 
> …
> 
> end
> 
> I now want to detach this report generation from the the Rails  
> controller so that I can generate these report in the background (maybe  
> using BackgroundDRB) without having to go through the rails controller.
> 
> I first though about using just ERB but this won’t suffice as custom  
> rails methods like “render :partial=\>…” wont work with ERB. I need  
> the full power of the rails templating system without going through the  
> controller.
> 
> Does anyone have any ideas how to do this? Any help is appreciated.
> 
> Thanks  
> Chris

Why aren’t you making the report available as an url? So you can have  
the report at [http://yourdomain/report](http://yourdomain/report) and call this url from your  
backgroundjob with

html = Net::HTTP.get(‘[www.yourdomain.com](http://www.yourdomain.com)’, ‘report’)

Let Rails do its stuff the right way and just consume the outcome.  
Not tested, but that would be my apporach.

Mike
