2010-07-02 18 views
5

Tôi thấy cảnh báo:Rails3: Cơ sở # after_update đã bị phản đối

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) 

tôi nên viết gì thay vì

def after_update 
    .... 
    end 

Trả lời

10

Bạn nên viết như sau:

after_update :your_custom_method # macro-style 

tại ít nhất bạn có thể vượt qua một khối thay vì phương pháp:

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

thông tin thêm tại đây: http://guides.rails.info/active_record_validations_callbacks.html (chọn tài liệu cạnh đường ray)

Các vấn đề liên quan