Class: Kublog::CategoriesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #is_admin?, #require_admin

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/kublog/categories_controller.rb', line 16

def create
  @category = Category.new(params[:category])
  respond_to do |format|
    if @category.save
      format.json { render :json => @category }
    else
      format.json { render :json => @category.errors.messages, :status => 'unprocessable_entity' }
    end
  end
end

#destroyObject



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

def destroy
  @category = Category.find(params[:id])
  @category.destroy
  respond_to do |format|
    format.json{ render :json => @category }
  end
end

#showObject



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

def show
  @category = Category.find(params[:id])
  @presenter = PostsPresenter.new(@category)
  respond_to do |format|
    format.atom { render "/kublog/posts/index", :layout => false, :content_type => 'text/xml' }
    format.rss  { render "/kublog/posts/index", :layout => false, :content_type => 'text/xml' }
    format.html { render "/kublog/posts/index" }
  end
end

#updateObject



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

def update
  @category = Category.find(params[:id])
  respond_to do |format|
    if @category.update_attributes(params[:category])
      format.json { render :json => @category }
    else
      format.json { render :json => @category.errors.messages, :status => 'unprocessable_entity' }
    end
  end
end