Last Updated: February 25, 2016
·
10.75K
· raysrashmi

persisted? && new_record? for checking existing record

new_record? we use for checking if object is saved or not

u=User.new

u.new_record? => true

There is a Active Record method persisted? to check if the object is exists in the sysytem

for example

u = User.findbyemail('rays@example.com')

u.persisted? => true

User.new.persisted? => false

2 Responses
Add your response

persisted not exactly opposite to the #new_record because it also checks if the object was destroyed.

over 1 year ago ·

Thats right. It check object is not new and not destroyed

over 1 year ago ·