Save view to file


#1

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.


#2

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.


#3

Jonathan,

Thank you very much! That worked very well.

Paul