feat: Generate short url view

stimulus links controller, tailwindcss setup, links controller post route, tests updated

Generate short links view
This commit is contained in:
Juan Rodriguez
2021-06-14 00:41:53 -05:00
parent e50da9b3e2
commit 3e8bdee17a
24 changed files with 527 additions and 89 deletions
+13 -7
View File
@@ -1,13 +1,9 @@
# frozen_string_literal: true
class LinksController < ApplicationController
def home
render 'links/home'
end
def redirect
@link = Link.find_by_slug(params[:slug])
def show
@link = Link.find_by_slug(link_params[:slug])
if @link.nil?
render file: "#{Rails.root}/public/404", status: :not_found
else
@@ -16,7 +12,17 @@ class LinksController < ApplicationController
end
end
def create
@link = Link.find_or_create_by(url: link_params[:url])
if @link.errors.any?
render json: @link.errors, status: :unprocessable_entity
else
render partial: 'links/show', locals: { link: @link }, status: :ok
end
end
def link_params
params.permit(:slug)
params.require(:link).permit(:url)
end
end