Determinar si el objeto ActiveRecord es Nuevo


¿Cómo puedo comprobar si un objeto ActiveRecord es nuevo o ya se conserva?

Author: ndn, 2011-10-21

2 answers

#new_record? hace exactamente eso:

object.new_record?
 248
Author: John Beynon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-11 13:59:53

Un ciclo de vida de un objeto ActiveRecord:

1.nuevo registro

item = Item.new
item.new_record? #=> true

2.persistió

item.save
item.persisted? #=> true

3.cambiado

item.name = "other"
item.changed? #=> true

4.destruido

item.destroy
item.destroyed? #=> true
 303
Author: Damien,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-07 18:10:09