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
Written by Rashmi
Related protips
2 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#