Files
bit/app/controllers/links_controller.rb
T
Juan Rodriguez d72ad2d43b feat: Links controller
Show method, Home page, redirection validation

LinksController show method
2021-06-13 20:34:41 -05:00

23 lines
433 B
Ruby

# frozen_string_literal: true
class LinksController < ApplicationController
def home
render 'links/home'
end
def show
@link = Link.find_by_slug(link_params[:slug])
if @link.nil?
render file: "#{Rails.root}/public/404", status: :not_found
else
@link.update(click_counter: @link.click_counter + 1)
redirect_to @link.url
end
end
def link_params
params.permit(:slug)
end
end