public
Description: El Dorado is a full-stack community web application written in Ruby/Rails.
Homepage: http://almosteffortless.com/eldorado/
Clone URL: git://github.com/trevorturk/el-dorado.git
el-dorado / app / controllers / categories_controller.rb
100644 54 lines (43 sloc) 1.335 kb
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
class CategoriesController < ApplicationController
  
  before_filter :require_admin, :except => [:index, :show]
 
  def index
    redirect_to forum_root_path
  end
  
  def show
    @category = Category.find(params[:id], :include => :forums)
    @forums = @category.forums
    @topics = Topic.paginate(:page => params[:page], :include => [:user, :forum, :last_poster], :order => 'topics.last_post_at desc', :conditions => ["forum_id in (?)", @forums.collect(&:id)])
    render(:template => "topics/index")
  end
  
  def new
  end
    
  def create
    @category = Category.new(params[:category])
    render :action => 'new' and return false unless @category.save
    redirect_to forum_root_path
  end
  
  def edit
    @category = Category.find(params[:id])
  end
  
  def update
    @category = Category.find(params[:id])
    if @category.update_attributes(params[:category])
      redirect_to @category
    else
      render :action => "edit"
    end
  end
    
  def destroy
    @category = Category.find(params[:id])
    if params[:confirm] != "1"
      flash[:notice] = "You must check the confirmation box"
      redirect_to confirm_delete_category_path(@category)
    else
      @category.destroy
      redirect_to forum_root_path
    end
  end
  
  def confirm_delete
    @category = Category.find(params[:id])
  end
    
end