Back

filters()

Name Type Required Default Description
through string Yes Function(s) to execute before or after the action(s).
type string No before Whether to run the function(s) before or after the action(s).
only string No Pass in a list of action names (or one action name) to tell Wheels that the filter function(s) should only be run on these actions.
except string No Pass in a list of action names (or one action name) to tell Wheels that the filter function(s) should be run on all actions except the specified ones.
placement string No append Pass in prepend to prepend the function(s) to the filter chain instead of appending.
1. Run a filter before all actions
// Always execute restrictAccess before every action
filters("restrictAccess");

2. Multiple filters before all actions
// Run both isLoggedIn and checkIPAddress before all actions
filters(through="isLoggedIn, checkIPAddress");

3. Exclude specific actions
// Run filters before all actions, except home and login
filters(through="isLoggedIn, checkIPAddress", except="home, login");

4. Limit filters to specific actions
// Only run ensureAdmin before the delete action
filters(through="ensureAdmin", only="delete");

5. Run filters after an action
// Run logAction after every action
filters(through="logAction", type="after");
Copied!