Count views to images

Hi,

I want to implement logic in Rail so that I can count number of views
to an image served by my server. Any suggestions on how to do it ?

How do I intercept request to an image , perform book keeping, then
redirect the request to the image ?

Thanks!

I want to implement logic in Rail so that I can count number of views
to an image served by my server. Any suggestions on how to do it ?

How do I intercept request to an image , perform book keeping, then
redirect the request to the image ?

Images should route straight thru your web server without ever touching Rails - or especially Ruby!

Ask this question on a forum that covers your web server. Reading its access.log to see which images are popular might be efficient, or might not!

Well actually i need to do more than counting the views. I need to log
information about the client and perform some tasks before serving the
image. I need to also do several database transactions.

Actually I can make the problem simple. The request can come to my
regular rails function. Thus, any request which comes to
http://myserver.com/controller/test should direct request to
http://myserver.com/images/my_precious.jpg

How do I do that ?

Thanks

Well actually i need to do more than counting the views. I need to log
information about the client and perform some tasks before serving the
image. I need to also do several database transactions.

Actually I can make the problem simple. The request can come to my
regular rails function. Thus, any request which comes to
http://myserver.com/controller/test should direct request to
http://myserver.com/images/my_precious.jpg

How do I do that ?

send_data, send_file, xsendfile

Fred

How about something like:

def my_action
  # some db transactions and other tasks
  redirect_to '/images/my_image.jpg'
end

then put the image in /public/images/my_image.jpg

This will prevent rails from having to serve the image (which isn’t
terribly efficient). The only problem is that anyone who directly
visits ‘http://www.example.com/images/my_image.jpg’ will see the image
and all your db transactions and other tasks will be skipped.

I hope that helps,
Paul