# Write Static File for View Output?

**URL:** <https://www.ruby-forum.com/t/write-static-file-for-view-output/166469>\
**Category:** Rails\
**Created:** [April 25, 2009, 6:59pm UTC](https://www.ruby-forum.com/t/write-static-file-for-view-output/166469 "2009-04-25T18:59:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [April 25, 2009, 6:59pm UTC](https://www.ruby-forum.com/t/write-static-file-for-view-output/166469/1 "2009-04-25T18:59:35Z")

</div>

Is it possible to save a view’s output into a static file rather than  
dynamically generate it each request?..

I’ve got a working controller method and view to select my db records  
and format them into a custom XML output, but I’d like to save the  
view output into “/public/data/{params[:id]}.xml”

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [April 25, 2009, 7:54pm UTC](https://www.ruby-forum.com/t/write-static-file-for-view-output/166469/2 "2009-04-25T19:54:34Z")

</div>

On Apr 25, 5:58 pm, Sav [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is it possible to save a view’s output into a static file rather than  
> dynamically generate it each request?..
> 
> I’ve got a working controller method and view to select my db records  
> and format them into a custom XML output, but I’d like to save the  
> view output into “/public/data/{params[:id]}.xml”

Sounds to me like you should read up on action controller’s caching  
support.

Fred

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [April 26, 2009, 1:11am UTC](https://www.ruby-forum.com/t/write-static-file-for-view-output/166469/3 "2009-04-26T01:11:36Z")

</div>

Just use page caching:

DataController  
caches\_page :show

def show  
# generate the XML  
end  
end

Now there will be a lot of files like:  
/public/data/1.xml  
/public/data/2.xml  
/public/data/3.xml  
…

Dmitry
