Class: CategoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/categories_controller.rb

Instance Method Summary collapse

Instance Method Details

#cmsObject

GET /categories GET /categories.xml



5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/categories_controller.rb', line 5

def cms
  if(@category = Category.find_by_title(params[:title]))
    @posts = @category.posts
    render 'categories/show'
  elsif(@post = Post.find(params[:title]))
    render 'posts/show'
  else
    render 'posts/notfound'
  end
end

#createObject

POST /categories POST /categories.xml



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/categories_controller.rb', line 54

def create
  @category = Category.new(params[:category])

  respond_to do |format|
    if @category.save
      format.html { redirect_to(@category, :notice => 'Category was successfully created.') }
      format.xml  { render :xml => @category, :status => :created, :location => @category }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /categories/1 DELETE /categories/1.xml



86
87
88
89
90
91
92
93
94
# File 'app/controllers/categories_controller.rb', line 86

def destroy
  @category = Category.find(params[:id])
  @category.destroy

  respond_to do |format|
    format.html { redirect_to(categories_url) }
    format.xml  { head :ok }
  end
end

#editObject

GET /categories/1/edit



48
49
50
# File 'app/controllers/categories_controller.rb', line 48

def edit
  @category = Category.find(params[:id])
end

#indexObject



15
16
17
18
19
20
21
22
# File 'app/controllers/categories_controller.rb', line 15

def index
  @categories = Category.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @categories }
  end
end

#newObject

GET /categories/new GET /categories/new.xml



38
39
40
41
42
43
44
45
# File 'app/controllers/categories_controller.rb', line 38

def new
  @category = Category.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @category }
  end
end

#showObject

GET /categories/1 GET /categories/1.xml



26
27
28
29
30
31
32
33
34
# File 'app/controllers/categories_controller.rb', line 26

def show
  @category = Category.find(params[:id])
  @posts = @category.posts

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @category }
  end
end

#updateObject

PUT /categories/1 PUT /categories/1.xml



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/categories_controller.rb', line 70

def update
  @category = Category.find(params[:id])

  respond_to do |format|
    if @category.update_attributes(params[:category])
      format.html { redirect_to(@category, :notice => 'Category was successfully updated.') }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @category.errors, :status => :unprocessable_entity }
    end
  end
end