From 31646d483fb670f9f3af7754fcdcf725978433d2 Mon Sep 17 00:00:00 2001 From: Jalen Young <120889301+BlueUnderBoy@users.noreply.github.com> Date: Sat, 19 Apr 2025 02:21:35 +0000 Subject: [PATCH 1/3] cree les fichiers de JS, et met a jour les autes fichiers --- app/controllers/comments_controller.rb | 6 ++++++ app/views/comments/_comment.html.erb | 21 ++++++++++++++++++--- app/views/comments/_form.html.erb | 4 ++-- app/views/comments/create.js.erb | 10 ++++++++++ app/views/comments/destroy.js.erb | 4 ++++ app/views/comments/edit.js.erb | 1 + app/views/comments/update.js.erb | 1 + 7 files changed, 42 insertions(+), 5 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 diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 28d0f47..194adc7 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -9,6 +9,9 @@ def new # GET /comments/1/edit def edit + respond_to do |format| + format.html + format.js end # POST /comments or /comments.json @@ -20,6 +23,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 { render template: "comments/create.js.erb" } #or you can just write "format.js" since folder and controller name are the same, template and action name are the same, and request format matches the file extension. Ruby will figure everything else out else format.html { render :new, status: :unprocessable_entity } format.json { render json: @comment.errors, status: :unprocessable_entity } @@ -33,6 +37,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 } @@ -46,6 +51,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" } end end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 845fd6a..8344e04 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,4 +1,4 @@ -