2015-10-01 11:56:40 -04:00
|
|
|
class LinksController < ApplicationController
|
|
|
|
before_action :set_link, only: [:show, :edit, :update, :destroy]
|
2015-10-08 15:18:21 -04:00
|
|
|
after_action :verify_authorized
|
2015-10-01 11:56:40 -04:00
|
|
|
|
|
|
|
def index
|
|
|
|
@links = Link.all
|
2015-10-08 15:18:21 -04:00
|
|
|
|
|
|
|
authorize Link
|
2015-10-01 11:56:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2015-10-08 15:18:21 -04:00
|
|
|
authorize @link
|
2015-10-01 11:56:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@link = Link.new
|
2015-10-08 15:18:21 -04:00
|
|
|
|
|
|
|
authorize @link
|
2015-10-01 11:56:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@link = Link.new(link_params)
|
|
|
|
|
2015-10-08 15:18:21 -04:00
|
|
|
authorize @link
|
|
|
|
|
2015-10-01 11:56:40 -04:00
|
|
|
if @link.save
|
|
|
|
redirect_to links_path, notice: 'Link was created'
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-10-08 15:18:21 -04:00
|
|
|
authorize @link
|
2015-10-01 11:56:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-10-08 15:18:21 -04:00
|
|
|
authorize @link
|
|
|
|
|
2015-10-01 11:56:40 -04:00
|
|
|
if @link.update(link_params)
|
|
|
|
redirect_to links_path, notice: 'Link was updated'
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-10-08 15:18:21 -04:00
|
|
|
authorize @link
|
|
|
|
|
2015-10-01 11:56:40 -04:00
|
|
|
@link.destroy
|
|
|
|
|
|
|
|
redirect_to 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
|