Rails 3: How to intercept any http request
===

Lets say I have an image at app/assets/images/privateimages/myrestrictedimage1.jpg
If I try to go directly to the image via url say with something like

     http://localhost:5555/assets/privateimages/myrestrictedimage1.jpg
I am able to view the image.

I would like to have a way to inspect any http request to decide if the user is allowed access to it.

I know I can use before_filter in controllers to do some preprocessing before continuing onto any of the controller actions but I dont think this will help me because I need to be attempting to do a controller action for this to take effect.

I have heard I might be able to do it with a rake task but after much searching I haven't found anything like what I am trying to do. Perhaps I have to create a ruby gem to do this but I have no clue how to do this.

Can anyone point me in the right direction? Thanks.

