added ajax/comment_controller
This commit is contained in:
parent
2d44eeef60
commit
50151453d8
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
json.partial! 'ajax/shared/status'
|
||||
json.render @render if @render
|
Loading…
Reference in New Issue