1class Admin::TagsController < Admin::AdminController |
|
2 before_action :require_sysadmin |
|
3 before_action :find_tags, only: [:index] |
|
4 before_action :find_tag, only: [:edit, :update, :destroy] |
|
5 before_action :build_tag, only: [:new, :create] |
|
6 before_action :destroy_tag, only: [:destroy] |
|
8 def index |
|
9 respond_to do |format| |
|
10 format.html
|
|
11 end |
|
12 end |
|
14 def new |
|
15 respond_to do |format| |
|
16 format.html
|
|
17 end |
|
18 end |
|
20 def create |
|
21 if @tag.save |
|
22 redirect_to_index_url notice: :tag_created |
|
23 else |
|
24 respond_to do |format| |
|
25 format.html { render :new } |
|
26 end |
|
27 end |
|
28 end |
|
30 def edit |
|
31 respond_to do |format| |
|
32 format.html
|
|
33 end |
|
34 end |
|
36 def update |
|
37 if @tag.update(tag_params) |
|
38 redirect_to_index_url notice: :tag_updated |
|
39 else |
|
40 respond_to do |format| |
|
41 format.html { render :edit } |
|
42 end |
|
43 end |
|
44 end |
|
46 def destroy |
|
47 redirect_to_index_url notice: :tag_deleted |
|
48 end |
|
50 private
|
|
52 def find_tags |
|
53 @tags = Tag.search(params) |
|
54 end |
|
56 def find_tag |
|
57 @tag = Tag.find(params[:id]) |
|
58 end |
|
60 def build_tag |
|
61 @tag = Tag.new(tag_params) |
|
62 end |
|
64 def destroy_tag |
|
65 @tag.destroy |
|
66 end |
|
68 def tag_params |
|
69 if params.key?(:tag) |
|
70 params.require(:tag).permit(:name, :description) |
|
71 else |
|
72 {}
|
|
73 end |
|
74 end |
|
76 def index_url |
|
77 admin_tags_url(params.slice(:q)) |
|
78 end |
|
80 def redirect_to_index_url(options = {}) |
|
81 redirect_to index_url, options
|
|
82 end |
|
83end |