本文介绍了Rails3:已弃用Base#after_update的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到警告:

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


推荐答案

您应输入以下内容:

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

此处有更多信息:(选择rails edge文档)

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

这篇关于Rails3:已弃用Base#after_update的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:47