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 ###



59
60
61
62
63
64
65
66
67
# File 'app/controllers/mongoid_forums/admin/groups_controller.rb', line 59

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
# File 'app/controllers/mongoid_forums/admin/groups_controller.rb', line 15

def create
  if @group = Group.create(params.require(:group).permit(:name, :moderator, :members))
    flash[:notice] = "Group created successfully"
    redirect_to [:admin, @group]
  else
    flash.now.alert = "Group could not be created"
    render :action => "new"
  end
end

#destroyObject



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

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

  if @group.destroy
    flash[:notice] = "Group destroyed successfully"
    redirect_to admin_groups_path
  else
    flash.now.alert = "Group could not be destroyed"
    redirect_to admin_groups_path
  end
end

#editObject



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

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



69
70
71
72
73
74
75
76
77
# File 'app/controllers/mongoid_forums/admin/groups_controller.rb', line 69

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



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

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



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

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