Should I extend or include ActiveModel:Validations:Callbacks:ClassMethods
or ActiveModel:Validations:Callbacks
?
What's the correct way to make before_validation, etc. work in an ActiveModel
Asked Answered
I got it to work like this:
class Foo
extend ActiveModel::Callbacks
include ActiveModel::Validations
include ActiveModel::Validations::Callbacks
before_validation :bar
def bar
# callback logic here
end
end
It's important that you have everything in that order.
© 2022 - 2024 — McMap. All rights reserved.