diff --git a/app/controllers/ajax/comment_controller.rb b/app/controllers/ajax/comment_controller.rb new file mode 100644 index 00000000..72e8d438 --- /dev/null +++ b/app/controllers/ajax/comment_controller.rb @@ -0,0 +1,22 @@ +class Ajax::CommentController < ApplicationController + def create + params.require :answer + params.require :comment + + answer = Answer.find(params[:answer]) + + begin + current_user.comment(answer, params[:comment]) + rescue ActiveRecord::RecordInvalid + @status = :rec_inv + @message = "Your comment is too long." + @success = false + return + end + + @status = :okay + @message = "Comment posted successfully." + @success = true + @render = render_to_string(partial: 'shared/comments', locals: { a: answer }) + end +end diff --git a/app/views/ajax/comment/create.json.jbuilder b/app/views/ajax/comment/create.json.jbuilder new file mode 100644 index 00000000..e63a494b --- /dev/null +++ b/app/views/ajax/comment/create.json.jbuilder @@ -0,0 +1,2 @@ +json.partial! 'ajax/shared/status' +json.render @render if @render \ No newline at end of file