I'm looking to pass logic to a model when attempting to save in order to disable specific validations.
I know of other solutions such as this one: skip certain validation method in Model This involves putting a temporary attribute on a model which I want to avoid.
I'd rather that has a solution that ends up looking like this:
@my_model.save(:skip_name_validation => true)
^ Is something like this possible in Rails 3?
For sure you can do this by performing a trick like:
class YourModel
attr_accessor :skip_name_validation
validate :validate_method, unless: :skip_name_validation
end
Now you can use it like:
@my_model.save(:skip_name_validation => true)