12

Should I extend or include ActiveModel:Validations:Callbacks:ClassMethods or ActiveModel:Validations:Callbacks?

K Everest
  • 1,565
  • 5
  • 15
  • 23

1 Answers1

23

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.

JonnieCache
  • 231
  • 1
  • 3