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

65 lines
988 B
Ruby
Raw Permalink Normal View History

2015-10-09 08:17:29 -04:00
class Admin::LinksController < Admin::BaseController
2015-10-01 11:56:40 -04:00
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
2015-10-09 08:17:29 -04:00
redirect_to admin_links_path, notice: 'Link was created'
2015-10-01 11:56:40 -04:00
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)
2015-10-09 08:17:29 -04:00
redirect_to admin_links_path, notice: 'Link was updated'
2015-10-01 11:56:40 -04:00
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
2015-10-09 08:17:29 -04:00
redirect_to admin_links_path, notice: 'Link was deleted'
2015-10-01 11:56:40 -04:00
end
private
def link_params
params.require(:link).permit(:name, :description)
end
def set_link
@link = Link.find(params[:id])
end
end