Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the correct way to make before_validation, etc. work in an ActiveModel

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

like image 843
K Everest Avatar asked Jan 20 '12 04:01

K Everest


1 Answers

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.

like image 90
JonnieCache Avatar answered Sep 30 '22 01:09

JonnieCache