I need to log the time at which a request is made. How can I get that info from a request object in rails 3?
You need to create your Rack middleware, which will add a timestamp to request. For instance (haven't checked it, but it gives you the idea):
module Middleware
class Timestamp
def initialize(app)
@app = app
end
def call(env)
env[:timestamp] = Time.now
@app.call(env)
end
end
end
And add it in application.rb (config.middleware.use)
The request.env does not seem to include a timestamp:
<% for item in request.env %>
<%= item %><br />
<% end %>
And I don't see anything related here: http://api.rubyonrails.org/classes/ActionDispatch/Request.html
Is it sufficient for your application to just set a timestamp in your controller in a before_filter?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With