Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails; save a rendered views html content to file

I'm trying to create a view with a download link to download the html source?

like image 957
user354250 Avatar asked May 31 '10 02:05

user354250


1 Answers

@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
like image 95
muirbot Avatar answered Oct 22 '22 21:10

muirbot