I'm trying to create a view with a download link to download the html source?
Asked
Active
Viewed 7,653 times
2 Answers
16
@Peter 's solution worked for me. Here is a code sample:
View:
<%= link_to 'download this page', object_path(@object, :download => true) %>
Controller:
def show # ... if params[:download] send_data(render_to_string, :filename => "object.html", :type => "text/html") else # render normally end end

muirbot
- 2,061
- 1
- 20
- 29
7
You can use render_to_string
instead of render, which will give you the page, then to download it use send_data
.

Peter
- 127,331
- 53
- 180
- 211
-
Thanks, I've seen that in other searches, but have trouble using it. Do you have any examples? – user354250 May 31 '10 at 03:04