adds create and destroy to the tags CRUD

This commit is contained in:
David Gil
2015-08-15 20:01:52 +02:00
parent 664f656fe3
commit a4ec38d752
8 changed files with 74 additions and 11 deletions

View File

@@ -1,22 +1,37 @@
class Admin::TagsController < Admin::BaseController
layout 'admin'
before_action :find_tag, only: [:update, :destroy]
respond_to :html, :js
def index
@tags = ActsAsTaggableOn::Tag.order(featured: :desc)
@tag = ActsAsTaggableOn::Tag.new
end
def create
ActsAsTaggableOn::Tag.create(tag_params)
redirect_to admin_tags_path
end
def update
@tag = ActsAsTaggableOn::Tag.find(params[:id])
@tag.update(tag_params)
redirect_to admin_tags_path
end
def destroy
@tag.destroy
redirect_to admin_tags_path
end
private
def tag_params
params.require(:tag).permit(:featured)
params.require(:tag).permit(:featured, :name)
end
def find_tag
@tag = ActsAsTaggableOn::Tag.find(params[:id])
end
end