gpt4 book ai didi

callback - 导轨3 : Base#after_update has been deprecated

转载 作者:行者123 更新时间:2023-12-02 06:27:42 25 4
gpt4 key购买 nike

我看到警告:

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)

我应该写什么而不是

  def after_update
....
end

最佳答案

你应该写如下:

after_update :your_custom_method # macro-style

至少你可以传递一个 block 而不是一个方法:

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

更多信息请点击:http://guides.rails.info/active_record_validations_callbacks.html (选择 Rails 边缘文档)

关于callback - 导轨3 : Base#after_update has been deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3166891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com