Sha256: bf5ad15f24f5cd32d5005a5723d0f8f09135d98f44ba3aff695fad0abefff634
Contents?: true
Size: 1.48 KB
Versions: 8
Compression:
Stored size: 1.48 KB
Contents
require_dependency 'notee/application_controller' module Notee class CommentsController < ActionController::Base before_action :set_comment, only: [:update, :destroy] def index comments = Comment.where(is_deleted: false).order(updated_at: :desc) render json: { status: 'success', comments: comments } end def show @comments = Comment.where(post_id: params[:id]) render json: { status: 'success', comments: @comments } end def create @comment = Comment.new(comment_params) if @comment.save render json: { status: 'success' } else render json: { status: 'failed' } end end def update respond_to do |format| if @comment.update(is_hidden: !@comment.is_hidden) format.json { render json: @comment, status: 200 } else format.json { render json: @comment.errors, status: :unprocessable_entity } end end end def destroy respond_to do |format| if @comment.update(is_deleted: true) format.json { render json: @comment, status: 200 } else format.json { render json: @comment.errors, status: :internal_server_error } end end end private def set_comment @comment = Comment.find_by(id: params[:id]) end # Only allow a trusted parameter "white list" through. def comment_params params.require(:comment).permit(:post_id, :content, :name, :email) end end end
Version data entries
8 entries across 8 versions & 1 rubygems