Class: UrlController

Inherits:
ApplicationController show all
Defined in:
app/controllers/url_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject

GET /short-url

This action fetches a single shortened url from the database and redirects the user to the original long url, with each hit the action saves a hit on the url, If the url is not found, a simple 404 template is rendered


10
11
12
13
14
15
16
# File 'app/controllers/url_controller.rb', line 10

def show
  if @url
    redirect_to @url.hit_and_return(ip: request.ip)
  else
    render file: 'public/404.html', status: :not_found
  end
end