Sha256: 0e102f4db7061db5125ecdce6435cd6b9efcc330f6eb70b41597fdeffb961fdd

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

class Shortener::ShortenedUrlsController < ActionController::Base

  # 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

2 entries across 2 versions & 1 rubygems

Version Path
shortener-0.1.2 app/controllers/shortener/shortened_urls_controller.rb
shortener-0.1.1 app/controllers/shortener/shortened_urls_controller.rb