1
0
Fork 0
dokkan-data-rails/app/controllers/admin/links_controller.rb

64 lines
988 B
Ruby

class Admin::LinksController < Admin::BaseController
before_action :set_link, only: [:show, :edit, :update, :destroy]
after_action :verify_authorized
def index
@links = Link.all
authorize Link
end
def show
authorize @link
end
def new
@link = Link.new
authorize @link
end
def create
@link = Link.new(link_params)
authorize @link
if @link.save
redirect_to admin_links_path, notice: 'Link was created'
else
render :new
end
end
def edit
authorize @link
end
def update
authorize @link
if @link.update(link_params)
redirect_to admin_links_path, notice: 'Link was updated'
else
render :edit
end
end
def destroy
authorize @link
@link.destroy
redirect_to admin_links_path, notice: 'Link was deleted'
end
private
def link_params
params.require(:link).permit(:name, :description)
end
def set_link
@link = Link.find(params[:id])
end
end