forked from publify/publify
-
Notifications
You must be signed in to change notification settings - Fork 1
/
categories_controller.rb
55 lines (48 loc) · 1.18 KB
/
categories_controller.rb
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
class Admin::CategoriesController < Admin::BaseController
cache_sweeper :blog_sweeper
def index; redirect_to :action => 'new' ; end
def edit; new_or_edit; end
def new
respond_to do |format|
format.html { new_or_edit }
format.js {
@category = Category.new
}
end
end
def destroy
destroy_a(Category)
end
private
def new_or_edit
@categories = Category.find(:all)
@category = case params[:id]
when nil
Category.new
else
Category.find(params[:id])
end
@category.attributes = params[:category]
if request.post?
respond_to do |format|
format.html { save_category }
format.js do
@category.save
@article = Article.new
@article.categories << @category
return render(:partial => 'admin/content/categories')
end
end
return
end
render 'new'
end
def save_category
if @category.save!
flash[:notice] = _('Category was successfully saved.')
else
flash[:error] = _('Category could not be saved.')
end
redirect_to :action => 'new'
end
end