Sha256: d1ef36812f09e047c2430e18a88713a93e174b58ada6eec47b587ab854d788e6
Contents?: true
Size: 968 Bytes
Versions: 3
Compression:
Stored size: 968 Bytes
Contents
class Shortener::ShortenedUrlsController < ActionController::Base # find the real link for the shortened link key and redirect def show # only use the leading valid characters token = /^([#{Shortener.key_chars.join}]*).*/.match(params[:id])[1] # pull the link out of the db sl = ::Shortener::ShortenedUrl.find_by_unique_key(token) if sl # don't want to wait for the increment to happen, make it snappy! # this is the place to enhance the metrics captured # for the system. You could log the request origin # browser type, ip address etc. Thread.new do sl.increment!(:use_count) ActiveRecord::Base.connection.close end # do a 301 redirect to the destination url redirect_to sl.url, :status => :moved_permanently else # if we don't find the shortened link, redirect to the root # make this configurable in future versions redirect_to '/' end end end
Version data entries
3 entries across 3 versions & 1 rubygems