Class: Shortenizer::UController

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

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/shortenizer/u_controller.rb', line 13

def create
  @url = Shortenizer::Url.new(url_params)

  if @url.save
    flash[:message] = "Your URL has been shortened..."
  else
    flash[:message] = "Error occured, please try again!"
  end

  redirect_to action: :show, shortlink: @url.shortlink
end

#indexObject



4
5
6
7
# File 'app/controllers/shortenizer/u_controller.rb', line 4

def index
  target = Url.find_by(shortlink: params[:shortlink]).target
  redirect_to target
end

#newObject



9
10
11
# File 'app/controllers/shortenizer/u_controller.rb', line 9

def new
  @url = Shortenizer::Url.new
end

#showObject



25
26
27
28
# File 'app/controllers/shortenizer/u_controller.rb', line 25

def show
  url_obj = Url.find_by(shortlink: params[:shortlink])
  @url = Shortenizer::UrlPresenter.new(url_obj, request)
end