From 3247180dfa776eb4109712387b7a8a5520ae068e Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 28 Jul 2015 20:32:53 +0200 Subject: [PATCH] responds with ajax to comment creation [#47] --- app/controllers/comments_controller.rb | 9 +++++---- app/views/comments/_form.html.erb | 2 +- app/views/comments/create.js.erb | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 app/views/comments/create.js.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 91a92e5ba..00fd20653 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,12 +1,13 @@ class CommentsController < ApplicationController before_action :authenticate_user! before_action :set_debate, :set_parent + respond_to :html, :js def create - comment = Comment.build(@debate, current_user, params[:comment][:body]) - comment.save! - comment.move_to_child_of(@parent) if reply? - redirect_to @debate, notice: "Comentario guardado" + @comment = Comment.build(@debate, current_user, params[:comment][:body]) + @comment.save! + @comment.move_to_child_of(@parent) if reply? + respond_with @comment end private diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 03b6caad7..11478e39b 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,7 +1,7 @@ <%= link_to comment_link_text(parent), "", class: "js-add-comment-link", data: {'id': dom_id(parent)} %>