Class: GroupsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/groups_controller.rb

Constant Summary

Constants included from Localization

Localization::LOCALIZED_STRINGS

Instance Method Summary collapse

Methods inherited from ApplicationController

in_place_edit_for, #initialize

Methods included from ApplicationHelper

#back_or_link_to, #detour?, #detour_to, #display_notice, #h, #image_button_to, #image_detour_to, #image_link_to, #image_link_to_remote, #insert, #record, #resolution_image, #t, #update_task, #with_detour

Methods included from Localization

#l, load_localized_strings, #valid_language?

Constructor Details

This class inherits a constructor from ApplicationController

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/groups_controller.rb', line 21

def create
  @group = Group.new(params[:group])
  if @group.save
    flash[:notice] = 'Group was successfully created.'
    back_or_redirect_to :action => 'list'
  else
    render :action => 'new'
  end
end

#destroyObject



47
48
49
50
# File 'app/controllers/groups_controller.rb', line 47

def destroy
  Group.find(params[:id]).destroy
  redirect_to :action => 'list'
end

#editObject



31
32
33
34
35
# File 'app/controllers/groups_controller.rb', line 31

def edit
  @group = Group.find(params[:id])
  @users = User.find(:all, :order => 'first_name, last_name')
  @groups = Group.find(:all, :order => 'name')
end

#indexObject



4
5
6
7
# File 'app/controllers/groups_controller.rb', line 4

def index
  list
  render :action => 'list'
end

#listObject



13
14
15
# File 'app/controllers/groups_controller.rb', line 13

def list
  @groups = Group.paginate({:page => params[:page]})
end

#newObject



17
18
19
# File 'app/controllers/groups_controller.rb', line 17

def new
  @group = Group.new
end

#set_memberObject



52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/groups_controller.rb', line 52

def set_member
  @group = Group.find(params[:id])
  @user = User.find(params[:user_id])
  if params[:value] == 'true'
    @group.users << @user unless @group.users.include? @user 
  else
    @group.users.delete @user
  end
  @users = User.find(:all)
end

#updateObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/groups_controller.rb', line 37

def update
  @group = Group.find(params[:id])
  if @group.update_attributes(params[:group])
    flash[:notice] = 'Group was successfully updated.'
    back_or_redirect_to :action => :edit, :id => @group
  else
    render :action => 'edit'
  end
end