Class: MongoidForums::Admin::ForumsController

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

Instance Method Summary collapse

Instance Method Details

#add_groupObject

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



58
59
60
61
62
63
64
# File 'app/controllers/mongoid_forums/admin/forums_controller.rb', line 58

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

  redirect_to admin_forum_path(@forum)
end

#createObject



16
17
18
19
20
21
22
23
24
# File 'app/controllers/mongoid_forums/admin/forums_controller.rb', line 16

def create
  if @forum = Forum.create(name: params[:forum][:name], category: params[:forum][:category])
    flash[:notice] = "Forum created successfully"
    redirect_to [:admin, @forum]
  else
    flash.now.alert = "Forum could not be created"
    render :action => "new"
  end
end

#destroyObject



46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/mongoid_forums/admin/forums_controller.rb', line 46

def destroy
  @forum = Forum.find(params[:id])
  if @forum.destroy
    flash[:notice] = "Forum destroyed successfully"
    redirect_to admin_forums_path
  else
    flash.now.alert = "Forum could not be destroyed"
    render :action => "index"
  end
end

#editObject



31
32
33
# File 'app/controllers/mongoid_forums/admin/forums_controller.rb', line 31

def edit
  @forum = Forum.find(params[:id])
end

#indexObject



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

def index
  @forums = Forum.all
end

#newObject



12
13
14
# File 'app/controllers/mongoid_forums/admin/forums_controller.rb', line 12

def new
  @forum = Forum.new
end

#remove_groupObject



66
67
68
69
70
71
72
# File 'app/controllers/mongoid_forums/admin/forums_controller.rb', line 66

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

  redirect_to admin_forum_path(@forum)
end

#showObject



26
27
28
29
# File 'app/controllers/mongoid_forums/admin/forums_controller.rb', line 26

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

#updateObject



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

def update
  @forum = Forum.find(params[:id])
  if @forum.update(forum_params)
    flash[:notice] = "Forum updated successfully"
    redirect_to @forum
  else
    flash.now.alert = "Forum could not be updated"
    render :action => "edit"
  end
end