kjb
kjb

Reputation: 3165

Easiest way to get the start time of a rails response?

I'm trying to compare the start time of a response to various places inside the code. Does rails have any magic that gives you response start time, or would I have to write my own middleware?

Upvotes: 1

Views: 123

Answers (1)

Fivell
Fivell

Reputation: 11929

I think the easiest way is to use custome middleware

Railscast : http://asciicasts.com/episodes/151-rack-middleware

Not tested example

  class TimestampMiddleware
    def initialize(app)
      @app = app
    end

    def call(env)
      env[:timestamp] = Time.now
      @app.call(env)
    end
  end

Register middleware

Rails::Initializer.run do |config|  
  config.middleware.use "TimestampMiddleware"  
end  

Upvotes: 1

Related Questions