I want to check if a model is being created in the before_save Rails callback. I also want to check if it has been changed (during upgrade).
thanks
Can you use new_record? to find out if you have a new object and changed? to see if something has changed:
new_record?
changed?
before_save :pancakes def pancakes if new_record? # Not in the database yet. elsif changed? # Already exists but it has unsaved changes. end end
Source: https://habr.com/ru/post/904500/More articles:Create id string for grouped view - sqldetect and reduce skew in opencv - c ++Javascript recommendations, why use a comma to declare a chain of functions / variables? - javascriptIs there a SaaS for registering user activity? - apiThe speed of using one button Google Plus. Mouse loading - javascriptcannot run Android emulator on Eclipse, although there are no errors - androidlight endless scroll with backbone.js - backbone.jsmod_rewrite for PHP REST API - restVisual Studio 2010 Customization Project Text Variable List - installerHow can I return the square box numeric data of all results using 1 mySQL query? - mathAll Articles