Sha256: 49611c38c7a5d56ea0681dae3d130807edb038b91361842ed62e7eeabcad0965
Contents?: true
Size: 858 Bytes
Versions: 1
Compression:
Stored size: 858 Bytes
Contents
class Shortener::ShortenedUrlsController < ::ApplicationController # find the real link for the shortened link key and redirect def show # pull the link out of the db sl = ::Shortener::ShortenedUrl.find_by_unique_key(params[:id]) 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shortener-0.1.0 | app/controllers/shortener/shortened_urls_controller.rb |