Forum: Ruby on Rails show render time on pages

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Simon S. (Guest)
on 2005-12-26 14:42
(Received via mailing list)
hello all!
is it possible to access the render time variables in the view? i would
like to show

Completed in 0.09574 (10 reqs/sec) | DB: 0.08729 (91%) | 200 OK
[http://localhost/person]

on each page like in the logs.

how can i do this?
Anocha Yimsiriwattana (Guest)
on 2005-12-26 17:22
(Received via mailing list)
Simon S. wrote:

> hello all!
> is it possible to access the render time variables in the view? i would
> like to show
>
> Completed in 0.09574 (10 reqs/sec) | DB: 0.08729 (91%) | 200 OK
> [http://localhost/person]
>
> on each page like in the logs.
>
> how can i do this?
If render time can only access in a controller, Try setting up a message
in
controller then. Moreover, you can use flash variable to do the job
since
you want the message to appear every page :),

Tom
Simon S. (Guest)
on 2005-12-26 18:25
(Received via mailing list)
Anocha Yimsiriwattana wrote:
> If render time can only access in a controller, Try setting up a message in
> controller then.

I don't know if it is accessible in the controller. I don't know where
to look for them...

> Moreover, you can use flash variable to do the job since
> you want the message to appear every page :),

Oh well. Once I get to them, displaying them will be the last of th
problems :)
Anocha Yimsiriwattana (Guest)
on 2005-12-26 18:43
(Received via mailing list)
Simon S. wrote:

> Oh well. Once I get to them, displaying them will be the last of th
> problems :)
Arr ... I thought you know how to access it in controller, my bad. I was
going to ask you how to do that too :P
Steve R. (Guest)
on 2005-12-26 21:56
(Received via mailing list)
By definition, if you can see the page, you got a 200 response so that's
very possibly not what you want. If render time is what you're after, an
approximate way to capture that is:

RAILS_ROOT/app/views/layouts/application.rb

<%= @content_for_layout %>
<%= sprintf('%f', (Time.now.usec - @start_time.usec).to_f / 1000000) %>


RAILS_ROOT/app/views/layouts/controller_to_time.rb

	def initialize
		@start_time = Time.now;
		super
	end

Naturally, a better way to do this would be to actually *change*
ApplicationController on the fly so this initialize code happens all the
time.

Regarding DB, that's kind of up to you, but a similar technique in
ActiveRecord would work.

By the way, Windows does not render the time to anywhere near the amount
of
precision *nix does.

Hope this helps.
This topic is locked and can not be replied to.