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

Methods included from Localization

#l, load_localized_strings, #valid_language?

Instance Method Details

#createObject



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

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



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

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

#editObject



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

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

#indexObject



2
3
4
5
# File 'app/controllers/groups_controller.rb', line 2

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

#listObject



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

def list
  @group_pages, @groups = paginate :groups, :per_page => 10
end

#newObject



15
16
17
# File 'app/controllers/groups_controller.rb', line 15

def new
  @group = Group.new
end

#set_memberObject



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

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)
  redirect_to :action => :edit, :id => @group
end

#updateObject



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

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