Created
October 3, 2012 05:59
-
-
Save swarut/3825305 to your computer and use it in GitHub Desktop.
Rails : A proper validation #rails #validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def appropriate_visibilities | |
unless (self.visibilities - self.user.roles).empty? | |
errors.add(:visibilities, "invalid visibilities assignment") | |
end | |
# Below is a bad one, change the visibilities silently. this is not a right behavior of validation | |
# self[:visibilities] = BIT_MASKER.mask( | |
# # This is assuming that self.visibilities, at least, must have :regular as its member | |
# # or we will end up getting visibilities = []. | |
# # See the comment on visibilities() above | |
# self.visibilities.reject{ |role| !self.user.roles.include?(role) && role != :regular } | |
# ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment