ruby - Rails 3: How to intercept any http request -
Let's say I have an AP / Assets / Image / Primetime / Maritrified Maze 1 I have an image on JPG if I directly image via Url
http: // localhost: 5555 / assets / personal / myrestrictedimage1.jpg I I am able to see the image.
I have a way to inspect any http request to determine whether the user has permission to access it or not.
I know that I can use before_filter in controllers to perform some rehearsal. Before continuing on any of the controller functions, but I do not think it will help me because I am trying to take a controlling action for this.
I have heard that I may be able to do this with a rake work, but after a lot of searching I did not get anything that I am trying to do. Maybe I have to make a ruby gem to do this but I have no clue how to do this.
Can anyone tell me in the right direction? Thank you.
I used rack middleware
The middleware class looks like this: / P>
class MyChecker def initialize (app) @app = App and def call (env) if (doccheck) #do stuff here check the path here # For example @ path = and ['pat_xfo'] '] And compare it to your right path # If you are good and then like @eP call (env) and #Estated like [301, {"location" => / Somewhere, "content type" = & gt; "Text / html"}, []] end-end Be sure to show your middleware by adding the following for the application.
class applications & lt; Rails :: App ... config.autoload_paths + =% W (# {config.root} / lib) #if, MyChecker is located somewhere in lib where you have config.middleware.use your middleware class "MyChecker" end < / Code>
Comments
Post a Comment