Class: MongoidForums::Admin::GroupsController

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

Instance Method Summary collapse

Instance Method Details

#add_memberObject

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


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

def add_member
  group = Group.find(params.require(:group_id))
  user = User.find(params[:user][:id])

  group.members << user.id unless group.members.include?(user.id)
  group.save

  redirect_to admin_group_path(group)
end

#createObject


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

def create
  @group =  Group.new(params.require(:group).permit(:name, :moderator, :members))
  if @group.save
    flash[:notice] = t("mongoid_forums.admin.group.created")
    redirect_to [:admin, @group]
  else
    flash[:notice] = t("mongoid_forums.admin.group.not_created")
    render :action => "new"
  end
end

#destroyObject


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

def destroy
  @group = Group.find(params[:id])
  @group.destroy
  flash[:notice] = t("mongoid_forums.admin.group.deleted")
  redirect_to admin_groups_path
end

#editObject


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

def edit
  @group = Group.find(params[:id])
end

#indexObject


7
8
9
# File 'app/controllers/mongoid_forums/admin/groups_controller.rb', line 7

def index
  @groups = Group.all
end

#newObject


11
12
13
# File 'app/controllers/mongoid_forums/admin/groups_controller.rb', line 11

def new
  @group = Group.new
end

#remove_memberObject


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

def remove_member
  group = Group.find(params.require(:group_id))
  user = User.find(params[:user][:id])

  group.members.delete(user.id)
  group.save

  redirect_to admin_group_path(group)
end

#showObject


41
42
43
44
45
# File 'app/controllers/mongoid_forums/admin/groups_controller.rb', line 41

def show
  @group = Group.find(params[:id])
  @group_members = @group.members.map{|member_id| User.find(member_id) }
  @users = User.all.select{ |user| !@group.members.include?(user.id) }
end

#updateObject


30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/mongoid_forums/admin/groups_controller.rb', line 30

def update
  @group = Group.find(params[:id])
  if @group.update_attributes(params.require(:group).permit(:name, :members))
    flash[:notice] = t("mongoid_forums.admin.group.updated")
    redirect_to [:admin, @group]
  else
    flash[:notice] = t("mongoid_forums.admin.group.not_updated")
    render :action => "edit"
  end
end