mirror of
https://github.com/wahyd4/Libr.git
synced 2026-08-10 05:16:04 +10:00
23 lines
694 B
Ruby
23 lines
694 B
Ruby
class Api::V1::CommentsController < ApplicationController
|
|
|
|
before_filter :allow_cors
|
|
before_filter :authenticate_user_from_token!, only: [:create]
|
|
skip_before_filter :verify_authenticity_token, :only => [:create]
|
|
|
|
def create
|
|
book = Book.find_by_id params[:book_id]
|
|
user = User.find_by_email params[:user_email]
|
|
comment = Comment.build_from(book, user.id, params[:content])
|
|
comment.save
|
|
render json: comment.to_json(include: {user: {only: [:avatar, :preferred_name]}})
|
|
|
|
end
|
|
|
|
def index
|
|
book = Book.find_by_id params[:book_id]
|
|
comments = book.comment_threads
|
|
render json: comments.to_json(include: {user: {only: [:avatar, :preferred_name]}})
|
|
end
|
|
|
|
end
|