Class: Url

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/url.rb

Overview

A url represents a single shortened url, each url has a key which stores the stores the short code that maps to the original_url

Instance Method Summary collapse

Instance Method Details

#hit_and_return(**args) ⇒ String

Creates a hit record then returns the original url

Parameters:

  • args (Hash)

    a has of options

Options Hash (**args):

  • :ip (String)

    The ip the request originated from

Returns:

  • (String)

    The original_url for the url object


16
17
18
19
20
# File 'app/models/url.rb', line 16

def hit_and_return(**args)
  ip = args.fetch :ip, nil
  hits.create(ip: ip)
  original_url
end