asciinema.org/app/controllers/api/comments_controller.rb

38 lines
834 B
Ruby
Raw Normal View History

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
2012-04-06 21:46:44 +00:00
respond_with CommentDecorator.decorate(@asciicast.comments)
2012-03-01 23:25:55 +00:00
end
def create
comment = Comment.new(params[:comment])
comment.asciicast = @asciicast
comment.user = current_user
2012-03-01 23:25:55 +00:00
comment.save
2012-03-01 23:25:55 +00:00
decorated_comment = CommentDecorator.new(comment)
respond_with decorated_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])
2012-04-09 14:33:29 +00:00
2012-03-04 13:37:30 +00:00
if comment.user == current_user
2012-04-09 14:33:29 +00:00
respond_with comment.destroy
2012-03-04 13:37:30 +00:00
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