Can someone please suggest why the following code does not work?
class User < ActiveRecord::Base
user = User.find_by_email_address(self.email_address)
self.id = user.id
self.registered = 1
This is for a user registration system, and the intention is that if
the user does not exist then it will be newly created, otherwise if a
placeholder account already exists (e.g. the user has been invited into
the system by a friend but has not yet accepted) then the placeholder
account will be updated.
I could do this in the controller, but this seems much cleaner. It is
unclear to me how to “pick up” the existing DB record, so that saving
updates the existing record. I thought assigning the primary key to the
existing record would suffice, but this does not appear to work.
Any help is greatly appreciated.