I would like to always have my model look to see if an object exists before saving. And if it does, then not to create a new object, but to use an existing one.
Is it possible to add this directly to the before_save ActiveRecord class of my model ?
I believe this is impossible because you can not change the value of self.
ActiveRecord already provides this functionality. You can do something like:
This will return the user from the database, if found, or a new user with the email set to the passed parameter. You can then use the object as you would otherwise and call save when you are done (which will update or create as needed).
More info on http://api.rubyonrails.org/classes/ActiveRecord/Base.html (search the page for find_or_initialize_by_)