From 93e7497d11f7bf27fecb73697776724ba4f54ee1 Mon Sep 17 00:00:00 2001 From: Eduardo Villa <151227243+evilla092@users.noreply.github.com> Date: Wed, 20 Mar 2024 19:24:27 +0000 Subject: [PATCH] Added ajax --- app/controllers/comments_controller.rb | 4 ++++ app/controllers/follow_requests_controller.rb | 2 ++ app/controllers/likes_controller.rb | 2 ++ app/views/comments/_comment.html.erb | 6 +++--- app/views/comments/_form.html.erb | 4 ++-- app/views/comments/create.js.erb | 9 +++++++++ app/views/comments/destroy.js.erb | 3 +++ app/views/comments/edit.js.erb | 1 + app/views/comments/update.js.erb | 2 ++ app/views/follow_requests/_follow_unfollow.html.erb | 4 ++-- app/views/follow_requests/_form.html.erb | 2 +- app/views/follow_requests/create.js.erb | 8 ++++++++ app/views/follow_requests/destroy.js.erb | 7 +++++++ app/views/likes/_form.html.erb | 4 ++-- app/views/likes/create.js.erb | 11 +++++++++++ app/views/likes/destroy.js.erb | 7 +++++++ app/views/photos/_likes.html.erb | 4 ++-- 17 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 app/views/comments/create.js.erb create mode 100644 app/views/comments/destroy.js.erb create mode 100644 app/views/comments/edit.js.erb create mode 100644 app/views/comments/update.js.erb create mode 100644 app/views/follow_requests/create.js.erb create mode 100644 app/views/follow_requests/destroy.js.erb create mode 100644 app/views/likes/create.js.erb create mode 100644 app/views/likes/destroy.js.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5b62df9..eac5e39 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,6 +34,7 @@ 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 } @@ -46,6 +48,7 @@ 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 } @@ -59,6 +62,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 end end diff --git a/app/controllers/follow_requests_controller.rb b/app/controllers/follow_requests_controller.rb index 9c30da7..21a133f 100644 --- a/app/controllers/follow_requests_controller.rb +++ b/app/controllers/follow_requests_controller.rb @@ -28,6 +28,7 @@ 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 } @@ -54,6 +55,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..d7ef279 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -27,6 +27,7 @@ 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 } @@ -53,6 +54,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 7b8dc14..74e89e7 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,4 +1,4 @@ -