ruby-on-railsrubyasset-pipeline

How to save a full html page in Rails


I'm trying to save a webpage from my rails 4 application to disk, using

send_data(render_to_string, :filename => "foo.html").

The file is saved alright, but the css is missing.

I tried adding the type attribute, like so:

send_data(render_to_string, :filename => "foo.html", :type => "text/html")

but it didn't help.

How can I save the file with all the css (and other assets potentially), so that if I click on the saved file I'll see the same thing that I attempted to save?


Solution

  • render_to_string renders only the HTML part. It returns exact the same string as the browser receives when he loads the HTML page. Stylesheets and other assets will be loaded in additional requests. Therefore, I only see one option: render_to_string an HTML template/layout with inline CSS.

    Another option might be to open the save as dialog with JavaScript. But there seems no standardized way to do so.