# Save view to file

**URL:** <https://www.ruby-forum.com/t/save-view-to-file/61929>\
**Category:** Rails\
**Created:** [May 29, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/save-view-to-file/61929 "2006-05-29T22:24:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [May 29, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/save-view-to-file/61929/1 "2006-05-29T22:24:12Z")

</div>

Hi,

I am trying to figure out a way to save the view of an action to a file.

I have an action call makehtml. It gets data from a database and create  
a view that display the result in a browser. I would like to save that  
result view page to a file in public/htmls for example.

Does anyone know how I can do this?

Thanks for all your help in advance.

---

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [May 30, 2006, 5:37am UTC](https://www.ruby-forum.com/t/save-view-to-file/61929/2 "2006-05-30T05:37:04Z")

</div>

You can probably use an after\_filter:

class MyController \< ApplicationController  
after\_filter :save\_html, :only =\> :makehtml

def makehtml  
# Do normal stuff  
end

def save\_html  
File.open(’/tmp/makehtml.html’, ‘w’) do |f|  
f.write response.body  
end  
end  
end

That should do it (untested).

-Jonathan.

---

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [May 31, 2006, 4:33am UTC](https://www.ruby-forum.com/t/save-view-to-file/61929/3 "2006-05-31T04:33:14Z")

</div>

Jonathan,

Thank you very much! That worked very well.

Paul
