Class: MongoidShortener::ShortenedUrlsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- MongoidShortener::ShortenedUrlsController
- Defined in:
- app/controllers/mongoid_shortener/shortened_urls_controller.rb
Instance Method Summary collapse
-
#translate ⇒ Object
find the real link for the shortened link key and redirect.
Instance Method Details
#translate ⇒ Object
find the real link for the shortened link key and redirect
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/mongoid_shortener/shortened_urls_controller.rb', line 4 def translate # pull the link out of the db sl = ShortenedUrl.where(:unique_key => params[:unique_key][1..-1]).first if sl sl.inc(:use_count, 1) # do a 301 redirect to the destination url head :moved_permanently, :location => sl.url else # if we don't find the shortened link, redirect to the root # make this configurable in future versions head :moved_permanently, :location => MongoidShortener.root_url end end |