Forum: Ruby on Rails save view to file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ffc48400d1044e22209aa8fdacc2e053?d=identicon&s=25 Paul (Guest)
on 2006-05-29 22:24
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.
631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-05-30 05:37
(Received via mailing list)
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.
Ffc48400d1044e22209aa8fdacc2e053?d=identicon&s=25 Paul (Guest)
on 2006-05-31 04:33
Jonathan,

Thank you very much!  That worked very well.

Paul
This topic is locked and can not be replied to.