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

37 lines
772 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
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
2012-03-02 20:50:19 +00:00
#TODO Add Authorization
2012-03-01 23:25:55 +00:00
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
raise Forbiden
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