Equivalent to View Page Source; No AJAX

I am developing a website that does not use AJAX.

What I would like to be able to do on the server side is find the point
in RoR (assuming it exists) where the HTML is “rendered” and capture
that string so that I can manipulate it for my purposes.

To be a little clearer, the user at their browser can do a View Page
Source and then save that HTML to a file. I would like to generate
(i.e. capture) exactly the contents of that string/file on the server
side so that I can save it on the SERVER.

I am not asking for the client to send back the contents of the View
Page Source back to the server. I do not wish to interfere with the
sending of the HTML to the client. I just want to get a copy of that
HTML so that I can save it to a file on the server and have that file
have exactly the same contents as a View Page Source and then Save File
as that file would be on the client.

Is this possible and/or easy to do?

On Nov 20, 4:19pm, Ralph S. [email protected] wrote:

Is this possible and/or easy to do?

You could probably do that from an after_filter - you should be able
to play around with response.body.

Fred

Perhaps try to override the content-type:

@headers["Content-Type"] = "text/plain; charset=utf-8"

Let us know if it works.

“José Mota” [email protected] wrote in post #962911:

Perhaps try to override the content-type:

@headers["Content-Type"] = "text/plain; charset=utf-8"

Let us know if it works.

I’m sorry, Jose, I do not understand this at all.

Frederick C. wrote in post #962809:

On Nov 20, 4:19pm, Ralph S. [email protected] wrote:

Is this possible and/or easy to do?

You could probably do that from an after_filter - you should be able
to play around with response.body.

Fred

Fred, this is exactly what I wanted! Thanks.


For information about after_filer, see page 485 in Agile Web
Development in Rails
by Dave T…

For the clueless (me), here’s a code snippet that works for me

class MarketingController < ApplicationController
include ApplicationHelper

after_filter :write_response_body

.
.
.

protected

@@prefix = ‘f:/xxx/’
def write_response_body
puts “#{FILE} @ #{LINE}”
# puts response.body.length
html_file_name_to_save =
@@prefix + params[‘controller’] + ‘/’ + params[‘action’] + ‘.html’
File.open(html_file_name_to_save,“w”) { |f| f << response.body }
end

end

Ralph S. wrote in post #962803:

I am developing a website that does not use AJAX.

What I would like to be able to do on the server side is find the point
in RoR (assuming it exists) where the HTML is “rendered” and capture
that string so that I can manipulate it for my purposes.

To be a little clearer, the user at their browser can do a View Page
Source and then save that HTML to a file. I would like to generate
(i.e. capture) exactly the contents of that string/file on the server
side so that I can save it on the SERVER.

I am not asking for the client to send back the contents of the View
Page Source back to the server. I do not wish to interfere with the
sending of the HTML to the client. I just want to get a copy of that
HTML so that I can save it to a file on the server and have that file
have exactly the same contents as a View Page Source and then Save File
as that file would be on the client.

Is this possible and/or easy to do?

Sure. Use render_to_string.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone