class GroupController ApplicationControlle def index list render actio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class GroupController < ApplicationController
def index
list
render :action => 'list'
end
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
if params[:collection_id]
@collection = Collection.find(params[:collection_id])
@groups = @collection.Groups
else
redirect_to :controller => 'collection', :action => 'list'
end
end
def show
@group = Group.find(params[:id])
end
def new
@group = Group.new
end
def create
@group = Collection.find(params[:collection_id]).Groups.create(params[:group])
if @group
flash[:notice] = 'Group was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@group = Group.find(params[:id])
end
def update
@group = Group.find(params[:id])
if @group.update_attributes(params[:group])
flash[:notice] = 'Group was successfully updated.'
redirect_to :action => 'show', :id => @group
else
render :action => 'edit'
end
end
def destroy
Group.find(params[:id]).destroy
redirect_to :action => 'list'
end
end