A Simple Way to Shorten Long URLs in RAILS.

  1. An active record model called shortened_url for storing the details of the shortened link including the click counter to store how many times a user visited the link and the information of the user to which the link belongs.
  2. A controller to redirect the user to the particular link, when they click on the shortened URL. This controller will get the actual link from the database.
  • For maintaining maximum google juice to the original URL, the Url’s Controller does a 301 redirect which is the recommended type of redirect.
  • Instead of using the model id, we are using a unique 6 character code.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store