I have an entity that looks something like this:
journal_name = author_first_name + ’ ’ + author_last_name
journal_email_address = journal_name + ‘-’ id
I had journal_name and journal_email_address implemented as attributes
on the Journal model, but the time came along where, for various
reasons, it has become valuable to also store that information in the
database. So, what I thought I’d do, in app/models/journal.rb:
self.journal_name = self.author_first_name + ’ ’ +
self.inbound_email = self.journal_name.gsub(/[^a-zA-Z0-9]/, ‘’) +
‘-’ + self.id.to_s
which works fine in the case of an update of an existing record.
However, it does not work in the case of a creation of a new record
because before saving self.id does not exist. The result was my e-
mail addresses are looking like “SallyJones-” as opposed to
Okay, I thought, “since I need an ID to work with I’ll move this to
after_save,” like so:
but that creates an infinite loop.
At this point, I’m sort of stumped for what to do…thoughts on how I
could make this work?