3

I want to give an export feature in my website allowing the user to download an html content that I've setup, including the css that comes with it (which is the same css I use in the entire website).

How can I give the user a button that downloads an html file that is just a view from one of my controller's actions?

Thank you.

Rodrigo Ruiz
  • 4,248
  • 6
  • 43
  • 75

1 Answers1

0

The option which worked for me was this. In the action you are willing to render as plain text just add this line:

render  content_type: 'text/plain'

This will output plain text version of your html page, but this wont put a whole css inline. If that is the goal as well, then you will have to define a seperate layout which will put raw version of your css inline.

EDIT:

In that case you probably could use HTML5 function:

<a href="path/to/file" download>Click here to download</a>

Source: Force a browser to save file as after clicking link

Community
  • 1
  • 1
  • I don't really want the txt version, I want the entire html with css just like when you save as a web archive on safari, but without having the trouble to create a separate css just for this export page – Rodrigo Ruiz Sep 18 '14 at 19:25