I have a User model object whose permission attribute is restricted by validates_inclusion_of to ['user','org_admin','site_admin']. When designing the create/edit form for this object, I don’t want to duplicate this list, in case it changes later. Is there a “Rails way” to do this, or should I just extract the list of valid values into an attribute accessible from outside of the instance?
I have a User model object whose permission attribute is restricted by validates_inclusion_of to
Share
If I really wanted to work with strings I would probably define a User::PERMISSIONS constance which includes the mentioned permissions.
A simplified form (using simple_form in the example)
It would be even neater to create a permissions model and just save the permission_id when you create a new user.
There are probably even better ways to do it so I’m looking forward to other answers.