2012-03-04 15:48:24 +00:00
|
|
|
class Api::CommentsController < ApplicationController
|
2012-03-01 23:25:55 +00:00
|
|
|
respond_to :json
|
|
|
|
|
2012-03-04 15:48:24 +00:00
|
|
|
before_filter :ensure_authenticated!, :only => [:create, :destroy]
|
2012-03-01 23:25:55 +00:00
|
|
|
before_filter :load_asciicast, :only => [:index, :create]
|
|
|
|
|
|
|
|
def index
|
|
|
|
respond_with @asciicast.comments
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@comment = Comment.new(params[:comment])
|
|
|
|
@comment.asciicast = @asciicast
|
|
|
|
@comment.user = current_user
|
|
|
|
|
|
|
|
@comment.save
|
|
|
|
|
2012-03-04 20:26:22 +00:00
|
|
|
respond_with @comment, :location => api_comment_url(@comment)
|
2012-03-01 23:25:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2012-03-04 13:37:30 +00:00
|
|
|
comment = Comment.find(params[:id])
|
|
|
|
if comment.user == current_user
|
|
|
|
respond_with comment.delete
|
|
|
|
else
|
2012-03-06 20:27:17 +00:00
|
|
|
raise Forbidden
|
2012-03-04 13:37:30 +00:00
|
|
|
end
|
2012-03-01 23:25:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_asciicast
|
|
|
|
@asciicast = Asciicast.find(params[:asciicast_id])
|
|
|
|
end
|
|
|
|
end
|