Rustam A. Gasanov

$ echo "Inspired developer's blog" > /dev/null

Custom Validation for Specific Action

| Comments

Recently I have faced with a situation when there was a need to build custom validation for a single controller action. Let’s say we have a User model with a role attribute. Administrator should have an ability to create a users(in protected area) with any role. And any guest should have an access to the public registration page, where he can select his role from the limited list of the registerable roles. So how can we implement a validation, which will work correctly for both administrator and public user registration pages? My solution described below.