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

我与影子孤独终老i 提交于 2019-12-04 00:07:30

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/8936906/whats-the-correct-way-to-make-before-validation-etc-work-in-an-activemodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!