Rails3: Base#after_update has been deprecated

匆匆过客 提交于 2019-12-07 04:56:08

问题


I see the warning:

DEPRECATION WARNING: Base#after_update has been deprecated, please use Base.after_update :method instead. (called from <class:City> at /home/petrushka/webdev/my_app/app/models/city.rb:4)

What should I write instead of

  def after_update
     ....
  end

回答1:


You should write as follow:

after_update :your_custom_method # macro-style

at least you can pass a block instead of a method:

after_update do |model| 
  model.name = model.name.capitalize unless model.name.blank?
end

more info here: http://guides.rails.info/active_record_validations_callbacks.html (choose rails edge documentation)



来源:https://stackoverflow.com/questions/3166891/rails3-baseafter-update-has-been-deprecated

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