Sha256: 7512470f1fdd05220765607a1673feace63f9ef01e207600e21a5a1d8538e608

Contents?: true

Size: 656 Bytes

Versions: 4

Compression:

Stored size: 656 Bytes

Contents

module MongoidShortener
  class ShortenedUrlsController < ApplicationController
    # find the real link for the shortened link key and redirect
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid_shortener-1.1.0 app/controllers/mongoid_shortener/shortened_urls_controller.rb
mongoid_shortener-1.0.3 app/controllers/mongoid_shortener/shortened_urls_controller.rb
mongoid_shortener-1.0.2 app/controllers/mongoid_shortener/shortened_urls_controller.rb
mongoid_shortener-1.0.1 app/controllers/mongoid_shortener/shortened_urls_controller.rb