Class: MongoidForums::Admin::CategoriesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/mongoid_forums/admin/categories_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_groupObject

Temporary Methods - Try Not To Cringe Too Much <3 ###



55
56
57
58
59
60
61
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 55

def add_group
  group = Group.find(params[:group][:id])
  @category.moderator_groups << group
  @category.save

  redirect_to admin_category_path(@category)
end

#createObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 22

def create
  if @category = Category.create(category_params)
    flash[:notice] = t("mongoid_forums.admin.category.created")
    redirect_to admin_categories_path
  else
    flash.now.alert = t("mongoid_forums.admin.category.not_created")
    render :action => "new"
  end
end

#destroyObject



47
48
49
50
51
52
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 47

def destroy
  @category = Category.find(params[:id])
  @category.destroy
  flash[:notice] = t("mongoid_forums.admin.category.deleted")
  redirect_to admin_categories_path
end

#editObject



32
33
34
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 32

def edit
  @category = Category.find(params[:id])
end

#indexObject



8
9
10
11
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 8

def index
  @forums = Forum.asc(:position)
  @categories = Category.asc(:position)
end

#newObject



18
19
20
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 18

def new
  @category = Category.new
end

#remove_groupObject



63
64
65
66
67
68
69
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 63

def remove_group
  group = Group.find(params[:group][:id])
  @category.moderator_groups.delete(group)
  @category.save

  redirect_to admin_category_path(@category)
end

#showObject



13
14
15
16
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 13

def show
  @category = Category.find(params[:id])
  @groups = Group.  all.where(moderator: true).select{ |group| !@category.moderator_groups.include?(group) }
end

#updateObject



36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/mongoid_forums/admin/categories_controller.rb', line 36

def update
  @category = Category.find(params[:id])
  if @category.update(category_params)
    flash[:notice] = t("mongoid_forums.admin.category.updated")
    redirect_to admin_categories_path
  else
    flash[:notice] = t("mongoid_forums.admin.category.not_updated")
    render :action => "edit"
  end
end