diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5b62df9..cf7d1ea 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -21,6 +21,7 @@ def new def edit respond_to do |format| format.html + format.js end end @@ -33,9 +34,11 @@ def create if @comment.save format.html { redirect_back fallback_location: root_path, notice: "Comment was successfully created." } format.json { render :show, status: :created, location: @comment } + format.js else format.html { render :new, status: :unprocessable_entity } format.json { render json: @comment.errors, status: :unprocessable_entity } + format.js end end end @@ -46,9 +49,11 @@ def update if @comment.update(comment_params) format.html { redirect_to root_url, notice: "Comment was successfully updated." } format.json { render :show, status: :ok, location: @comment } + format.js else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @comment.errors, status: :unprocessable_entity } + format.js end end end @@ -59,6 +64,7 @@ def destroy respond_to do |format| format.html { redirect_back fallback_location: root_url, notice: "Comment was successfully destroyed." } format.json { head :no_content } + format.js {render template: "comments/destroy.js.erb"} end end diff --git a/app/controllers/follow_requests_controller.rb b/app/controllers/follow_requests_controller.rb index 9c30da7..fa2b590 100644 --- a/app/controllers/follow_requests_controller.rb +++ b/app/controllers/follow_requests_controller.rb @@ -28,9 +28,11 @@ def create if @follow_request.save format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully created." } format.json { render :show, status: :created, location: @follow_request } + format.js else format.html { render :new, status: :unprocessable_entity } format.json { render json: @follow_request.errors, status: :unprocessable_entity } + format.js end end end @@ -41,9 +43,11 @@ def update if @follow_request.update(follow_request_params) format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully updated." } format.json { render :show, status: :ok, location: @follow_request } + format.js else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @follow_request.errors, status: :unprocessable_entity } + format.js end end end @@ -54,6 +58,7 @@ def destroy respond_to do |format| format.html { redirect_back fallback_location: root_url, notice: "Follow request was successfully destroyed." } format.json { head :no_content } + format.js end end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 49affd3..a03a604 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -27,9 +27,11 @@ def create if @like.save format.html { redirect_back fallback_location: root_url, notice: "Like was successfully created." } format.json { render :show, status: :created, location: @like } + format.js else format.html { render :new, status: :unprocessable_entity } format.json { render json: @like.errors, status: :unprocessable_entity } + format.js end end end @@ -40,9 +42,11 @@ def update if @like.update(like_params) format.html { redirect_to @like, notice: "Like was successfully updated." } format.json { render :show, status: :ok, location: @like } + format.js else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @like.errors, status: :unprocessable_entity } + format.js end end end @@ -53,6 +57,7 @@ def destroy respond_to do |format| format.html { redirect_back fallback_location: root_url, notice: "Like was successfully destroyed." } format.json { head :no_content } + format.js end end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 25bdd33..3b1960c 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,4 +1,4 @@ -
  • +
  • <%= image_tag comment.author.avatar_image, class: "rounded-circle mr-2", width: 36 %>
    @@ -9,11 +9,11 @@
    <% if current_user == comment.author %> - <%= link_to edit_comment_path(comment), class: "btn btn-link btn-sm text-muted" do %> + <%= link_to edit_comment_path(comment), class: "btn btn-link btn-sm text-muted", remote:true do %> <% end %> - <%= link_to comment, method: :delete, class: "btn btn-link btn-sm text-muted" do %> + <%= link_to comment, method: :delete, class: "btn btn-link btn-sm text-muted", remote: true do %> <% end %> <% end %> diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index f289224..a9ba4fa 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,5 +1,5 @@ -
  • - <%= form_with(model: comment) do |form| %> +
  • + <%= form_with(model: comment, local: false) do |form| %> <% if comment.errors.any? %>