Added edit and cancel button

This commit is contained in:
2024-08-04 13:26:31 +02:00
parent ed0c4408ca
commit 54e0cd5e45
5 changed files with 41 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
class JobsController < ApplicationController
before_action :set_job, only: %i[show edit update destroy]
before_action :set_job, only: %i[show edit update destroy cancel]
# GET /jobs or /jobs.json
def index
@@ -36,7 +36,7 @@ class JobsController < ApplicationController
def update
respond_to do |format|
if @job.update(job_params)
format.html { redirect_to job_url(@job), notice: 'Job was successfully updated.' }
format.html { redirect_to jobs_url, notice: 'Job was successfully updated.' }
format.json { render :show, status: :ok, location: @job }
else
format.html { render :edit, status: :unprocessable_entity }
@@ -55,6 +55,16 @@ class JobsController < ApplicationController
end
end
def cancel
@job.canceled! if @job.able_to_cancel?
respond_to do |format|
format.turbo_stream {} # view is updated from model broadcast
format.html { redirect_to jobs_url, notice: 'Job was successfully canceled.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.