asciinema.org/app/controllers/api/comments_controller.rb
2012-03-04 21:26:22 +01:00

37 lines
772 B
Ruby

class Api::CommentsController < ApplicationController
respond_to :json
before_filter :ensure_authenticated!, :only => [:create, :destroy]
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
respond_with @comment, :location => api_comment_url(@comment)
end
#TODO Add Authorization
def destroy
comment = Comment.find(params[:id])
if comment.user == current_user
respond_with comment.delete
else
raise Forbiden
end
end
private
def load_asciicast
@asciicast = Asciicast.find(params[:asciicast_id])
end
end