Hi Rai,
This is untested code, hope it works..
Class MyTimer
attr_reader :elapsed_time
def initiailize
@elapsed_time = nil
end
def before_filter
@start_time = Time.now
end
def after_filter
@end_time = Time.now
@elapsed_time = @end_time - @start_time
end
end
in our layout.rhtml at the bottom, i guess u can put this code.
<div> Time take to render <%= @elapsed_time %> </div>
And in application.rb (controller)
require ''mytimer''
class Application < ActionController::Base
around_filter MyTimer.new
end
P.s:
The above code is untested, you can further optimize it. Sorry, i
don''t have ruby installed in this system.
May find syntax error.
Hope it works,
Regards,
Raghu Kumar K
On Nov 12, 3:10 pm, voodoorai2000
<voodoorai2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> If an admin is logged in, I''m trying to display how long the page
took
> to render, somewhere at the bottom of the page.
>
> I tried with an around_filter :time_an_action in application.rb
>
> def time_an_action
> started = Time.now
> yield
> @time_to_render = Time.now - started
> end
>
> In the layout I added this line:
> <%= @time_to_render%>
>
> However, as the time_an_action method has already yielded the page
> before the instance variable @time_to_render has been given a value,
> it does not display it.
>
> Trying to execute an AJAX call inside the filter or redirecting to
> another action, for example:
> def time_an_action
> started = Time.now
> yield
> @time_to_render = Time.now - started
> redirect_to :controller => "admin", :action =>
"display_time"
> end
>
> def display_time
> render :update do |page|
> page.replace_html "time_to_render", @time_to_render
> end
> end
>
> Gives the error of "You can''t render or redirect twice in the
same
> action"...
>
> Any suggestions?
>
> Thanks!
>
> Rai
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---