In my User model, I have the usual email suspects, first_name, last_name, password, etc.
I have several cases where I need to skip all or some of the checks.
I currently have a condition that looks something like this:
validates :first_name, presence: :true, etc..., unless: :skip_first_name_validation?
validates :last_name, presence: :true, etc..., unless: :skip_last_name_validation?
validates :email, presence: :true, etc..., unless: :skip_email_validation?
Of course I also have:
attr_accessor :skip_first_name_validation, :skip_last_name_validation, etc.
And then I use private methods to check the status of each of them:
def skip_first_name_validation?
skip_first_name_validation
end
def skip_last_name_validation?
skip_last_name_validation
end
def skip_email_validation?
skip_email_validation
end
etc..
From there, when I need to skip checks, I just assign each of these guys a value truein my controller.
So, while all this works great, I wonder if there is a more elegant way?
Ideally, it would be nice if I could use a simple conditional attribute for each attribute in my models:
:skip_validation?
And in my controllers just do something like:
skip_validation(:first_name, :last_name, :password) = true
- , ? gem/library, , . .