Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Filters23 are similar to action interceptors in that they give you the ability to execute logic before and after an action. They differ from action interceptors in that they are more flexible and can be used in situations other than actions. For example, you can define a filter that applies across multiple controllers.
Let's see how you can use filters to simplify the UserController. The UserController's edit, delete, and update actions all contain guard logic that allows users to edit only their own user data. The actions contain logic similar to Listing 5-40.
Listing 5-40. User Modification Guard
. . .
if (session.user.id != params.id) {
flash.message = "You can only edit yourself"
redirect(action:list)
return
}
. . .