Filters are methods that are run before, after or “around” a controller action.
Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application.
Before filters may halt the request cycle. A common before filter is one which requires that a user is logged in for an action to be run.
Before filters are run on requests before the request gets to the controller’s action. It can return a response itself and completely bypass the action.
The most common use of before filters is validating a user’s authentication before granting them access to the action designated to handle their request. I’ve also seen them used to load a resource from the database, check permissions on a resource, or manage redirects under other circumstances.
After filters are run after the action completes. It can modify the response. Most of the…
View original post 115 more words