Class: Virgo::Admin::CategoriesController

Inherits:
BaseController show all
Defined in:
app/controllers/virgo/admin/categories_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
# File 'app/controllers/virgo/admin/categories_controller.rb', line 26

def create
  @category = Category.new(category_params.merge(created_by: current_user))

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

        render json: {
          status: :success,
          html: render_content('success_modal', layout: false),
          categories_form_partial: render_content(partial: '/virgo/admin/posts/categories_form')}
      }
      fmt.html {
        flash[:notice] = "Category added successfully"
        redirect_to admin_categories_path
      }
    else
      fmt.json {
        render json: {status: :err, html: render_content('modal_form', layout: false)}
      }
      fmt.html {
        render 'new'
      }
    end
  end
end

#destroyObject



67
68
69
70
71
72
73
# File 'app/controllers/virgo/admin/categories_controller.rb', line 67

def destroy
  @category.destroy

  flash[:notice] = "Category deleted"

  redirect_to admin_categories_path
end

#editObject



55
56
# File 'app/controllers/virgo/admin/categories_controller.rb', line 55

def edit
end

#indexObject



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

def index
  if params[:sort].nil?
    flash.keep
    redirect_to admin_categories_path(sort: 'navbar_weight') and return
  end

  @categories = Category.visible.order(sort_order).with_post_count.page(params[:page])
end


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

def modal_form
  @category = Category.new

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

#newObject



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

def new
  @category = Category.new
end

#updateObject



58
59
60
61
62
63
64
65
# File 'app/controllers/virgo/admin/categories_controller.rb', line 58

def update
  if @category.update(category_params)
    flash[:notice] = "Category updated successfully"
    redirect_to admin_categories_path
  else
    render 'edit'
  end
end