I have a Rails application where people have a profile page - http://prettylongdomainname.com/profile_username
To create a profile username, I use the before_create AR hook in my model:
before_create :generate_username
def generate_username
self.username = a_user_name_i_generated
end
I would also like to keep the shortened URL in my user profile so that when they exchange things, I can automatically link to their profile page. I decided to use the bit.ly API to shorten the URL, but I'm not quite sure where I should put the code.
It makes sense that I have to save the shortened URL when creating the user, especially immediately after creating the profile_username username. However, I need to make an HTTP request in the bit.ly API in order to get the shortened URL.
Does anyone know a better way to do this?
Thank!
source
share