Forum: Ruby on Rails is there an activerecord method like "FIND EXISTING OR CREATE NEW IF NONE FOUND"?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Greg H. (Guest)
on 2008-12-22 05:39
(Received via mailing list)
Just wondering if rails has a method to look for an existing record and
return it, but if it's not existing then create a new record.   (i.e.
"FIND
EXISTING OR CREATE NEW IF NONE FOUND"?)

Then when finished updating one could use the existing "save" method
which
caters for either a new or updated record already

Thanks
snacktime (Guest)
on 2008-12-22 05:52
(Received via mailing list)
Yes, look at dynamic attribute based finders in the activercord docs.
http://api.rubyonrails.org/classes/ActiveRecord/Base.html.

Chris

On Sun, Dec 21, 2008 at 7:39 PM, Greg H. <
Greg H. (Guest)
on 2008-12-22 06:20
(Received via mailing list)
arr thanks - I thought I'd seen them somewhere - I'd been looking
through
the method names (c.f. content of the doc)
This topic is locked and can not be replied to.