Class: Virgo::Admin::TagsController

Inherits:
BaseController show all
Defined in:
app/controllers/virgo/admin/tags_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#authorize_admin_user, #search, #set_is_admin_view

Methods included from RenderHelper

#render_content, #with_format

Methods included from Virgo::ApplicationHelper

#action?, #admin?, #admin_access?, #admin_view?, #alerts, #base_errors, #category_timestamp, #column_timestamp, #compact_html, #controller?, #decode_html_entities, #expanded_post_url, #is_admin_view?, #page_url, #post_time_format, #post_timestamp, #production?, #redis_timestamp_key_for, #site, #site_key, #superuser?, #tabbed_param, #word_count

Instance Method Details

#createObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/virgo/admin/tags_controller.rb', line 26

def create
  @tag = Tag.new(tag_params.merge(created_by: current_user))

  respond_to do |fmt|
    if @tag.save
      fmt.json {
        @post = Post.find_by(id: params[:post_id])
        @post.tags << @tag unless (@post.nil? || @post.tags.include?(@tag))

        flash.now[:success] = "Tag successfully added! If you would like to add more tags you can do so below. Otherwise, close this pop-up."

        render json: {
          status: :success,
          tag: @tag,
          html: render_content('modal_form', layout: false, locals: {tag: Tag.new})
        }
      }
      fmt.html {
        flash[:notice] = "Tag added successfully"
        redirect_to admin_tags_path
      }
    else
      fmt.json {
        render json: {status: :err, html: render_content('modal_form', layout: false)}
      }
      fmt.html {
        render 'new'
      }
    end
  end

end

#destroyObject


71
72
73
74
75
76
77
# File 'app/controllers/virgo/admin/tags_controller.rb', line 71

def destroy
  @tag.destroy

  flash[:notice] = "Tag deleted"

  redirect_to admin_tags_path
end

#editObject


59
60
# File 'app/controllers/virgo/admin/tags_controller.rb', line 59

def edit
end

#indexObject


7
8
9
10
11
12
13
14
# File 'app/controllers/virgo/admin/tags_controller.rb', line 7

def index
  if params[:sort].blank? && filter_params.all_blank?
    flash.keep
    redirect_to admin_tags_path(sort: 'name') and return
  end

  @tags = Tag.search(filter_params).with_post_count.order(sort_order).page(params[:page])
end

20
21
22
23
24
# File 'app/controllers/virgo/admin/tags_controller.rb', line 20

def modal_form
  @tag = Tag.new

  render json: {status: :success, html: render_content('modal_form', layout: false)}
end

#newObject


16
17
18
# File 'app/controllers/virgo/admin/tags_controller.rb', line 16

def new
  @tag = Tag.new
end

#updateObject


62
63
64
65
66
67
68
69
# File 'app/controllers/virgo/admin/tags_controller.rb', line 62

def update
  if @tag.update(tag_params)
    flash[:notice] = "Tag updated successfully"
    redirect_to admin_tags_path
  else
    render 'edit'
  end
end