Class: Kublog::CommentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #is_admin?, #require_admin

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/kublog/comments_controller.rb', line 7

def create
  @post = Post.find(params[:post_id])
  @comment = @post.comments.build(params[:comment])
  respond_to do |format|
    if @comment.save
      format.json { render :json => @comment}
    else
      format.json { render :json => @comment.errors.to_json, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



19
20
21
22
23
24
25
26
# File 'app/controllers/kublog/comments_controller.rb', line 19

def destroy
  @post = Post.find(params[:post_id])
  @comment = @post.comments.find(params[:id])
  @comment.destroy
  respond_to do |format|
    format.json{ render :json => @comment }
  end
end