2024-09-05 22:54:38 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-07-26 00:59:00 +02:00
|
|
|
class LinksController < ApplicationController
|
|
|
|
|
before_action :set_link, only: %i[show edit update destroy]
|
|
|
|
|
|
|
|
|
|
# GET /links
|
|
|
|
|
def index
|
|
|
|
|
@links = Link.all
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# GET /links/1
|
2024-09-05 22:54:38 +02:00
|
|
|
def show; end
|
2024-07-26 00:59:00 +02:00
|
|
|
|
|
|
|
|
# GET /links/new
|
|
|
|
|
def new
|
|
|
|
|
@link = Link.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# GET /links/1/edit
|
2024-09-05 22:54:38 +02:00
|
|
|
def edit; end
|
2024-07-26 00:59:00 +02:00
|
|
|
|
|
|
|
|
# POST /links
|
|
|
|
|
def create
|
|
|
|
|
@link = Link.new(link_params)
|
|
|
|
|
|
|
|
|
|
if @link.save
|
2024-09-05 22:54:38 +02:00
|
|
|
redirect_to @link, notice: "Link was successfully created."
|
2024-07-26 00:59:00 +02:00
|
|
|
else
|
|
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# PATCH/PUT /links/1
|
|
|
|
|
def update
|
|
|
|
|
if @link.update(link_params)
|
2024-09-05 22:54:38 +02:00
|
|
|
redirect_to @link, notice: "Link was successfully updated.", status: :see_other
|
2024-07-26 00:59:00 +02:00
|
|
|
else
|
|
|
|
|
render :edit, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# DELETE /links/1
|
|
|
|
|
def destroy
|
|
|
|
|
@link.destroy!
|
2024-09-05 22:54:38 +02:00
|
|
|
redirect_to links_url, notice: "Link was successfully destroyed.", status: :see_other
|
2024-07-26 00:59:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
|
|
|
def set_link
|
|
|
|
|
@link = Link.find(params[:id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
|
|
|
def link_params
|
2024-09-11 20:44:33 +02:00
|
|
|
params.require(:link).permit(:url, :text, :description, :link_category_id)
|
2024-07-26 00:59:00 +02:00
|
|
|
end
|
|
|
|
|
end
|