hello the error is that I'm not saving the id as a string in the variable
fullnumid I just want to be saved when they are created, thanks
after_create :guardar
def guardar
self.fullnumid = self.id.to_s
end
hello the error is that I'm not saving the id as a string in the variable
fullnumid I just want to be saved when they are created, thanks
after_create :guardar
def guardar
self.fullnumid = self.id.to_s
end
You need to save the object after assigning the value to fullnumid
; you can do it with save!
or with update!
:
With save!
:
def guardar
self.fullnumid = id.to_s
save!
end
With update!
:
def guardar
update!(fullnumid: id.to_s)
end
You may notice the use of save!
and update!
(with !
), which is useful so that, in case of failure, an error is thrown (if you remove the !
it also works, but you can not see the error in case the record does not update).