categories_controller.rb
977 Bytes
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
class CategoriesController < EnvironmentAdminController
helper :categories
def index
@categories = environment.top_level_categories
end
# posts back
def new
@category = Category.new(params[:category])
@category.environment = environment
if params[:parent_id]
@category.parent = environment.categories.find(params[:parent_id])
end
if request.post?
begin
@category.save!
redirect_to :action => 'index'
rescue Exception => e
render :action => 'new'
end
end
end
# posts back
def edit
begin
@category = environment.categories.find(params[:id])
if request.post?
@category.update_attributes!(params[:category])
redirect_to :action => 'index'
end
rescue Exception => e
render :action => 'edit'
end
end
post_only :remove
def remove
environment.categories.find(params[:id]).destroy
redirect_to :action => 'index'
end
end