Scaffold job model
This commit is contained in:
70
app/controllers/jobs_controller.rb
Normal file
70
app/controllers/jobs_controller.rb
Normal file
@@ -0,0 +1,70 @@
|
||||
class JobsController < ApplicationController
|
||||
before_action :set_job, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /jobs or /jobs.json
|
||||
def index
|
||||
@jobs = Job.all
|
||||
end
|
||||
|
||||
# GET /jobs/1 or /jobs/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /jobs/new
|
||||
def new
|
||||
@job = Job.new
|
||||
end
|
||||
|
||||
# GET /jobs/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /jobs or /jobs.json
|
||||
def create
|
||||
@job = Job.new(job_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @job.save
|
||||
format.html { redirect_to job_url(@job), notice: "Job was successfully created." }
|
||||
format.json { render :show, status: :created, location: @job }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @job.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /jobs/1 or /jobs/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @job.update(job_params)
|
||||
format.html { redirect_to job_url(@job), notice: "Job was successfully updated." }
|
||||
format.json { render :show, status: :ok, location: @job }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
format.json { render json: @job.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /jobs/1 or /jobs/1.json
|
||||
def destroy
|
||||
@job.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to jobs_url, notice: "Job was successfully destroyed." }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_job
|
||||
@job = Job.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def job_params
|
||||
params.require(:job).permit(:operator_id_id, :costumer_id_id, :operator_firstname, :operator_lastname, :costumer_firstname, :costumer_lastname, :paid, :printed_at, :intern, :cost_center, :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan)
|
||||
end
|
||||
end
|
||||
2
app/helpers/jobs_helper.rb
Normal file
2
app/helpers/jobs_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module JobsHelper
|
||||
end
|
||||
4
app/models/job.rb
Normal file
4
app/models/job.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Job < ApplicationRecord
|
||||
belongs_to :operator_id
|
||||
belongs_to :costumer_id
|
||||
end
|
||||
92
app/views/jobs/_form.html.erb
Normal file
92
app/views/jobs/_form.html.erb
Normal file
@@ -0,0 +1,92 @@
|
||||
<%= form_with(model: job, class: "contents") do |form| %>
|
||||
<% if job.errors.any? %>
|
||||
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
|
||||
<h2><%= pluralize(job.errors.count, "error") %> prohibited this job from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% job.errors.each do |error| %>
|
||||
<li><%= error.full_message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :operator_id_id %>
|
||||
<%= form.text_field :operator_id_id, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :costumer_id_id %>
|
||||
<%= form.text_field :costumer_id_id, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :operator_firstname %>
|
||||
<%= form.text_field :operator_firstname, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :operator_lastname %>
|
||||
<%= form.text_field :operator_lastname, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :costumer_firstname %>
|
||||
<%= form.text_field :costumer_firstname, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :costumer_lastname %>
|
||||
<%= form.text_field :costumer_lastname, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :paid %>
|
||||
<%= form.check_box :paid, class: "block mt-2 h-5 w-5" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :printed_at %>
|
||||
<%= form.datetime_field :printed_at, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :intern %>
|
||||
<%= form.check_box :intern, class: "block mt-2 h-5 w-5" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :cost_center %>
|
||||
<%= form.text_field :cost_center, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a0 %>
|
||||
<%= form.number_field :number_of_plans_a0, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a1 %>
|
||||
<%= form.number_field :number_of_plans_a1, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a2 %>
|
||||
<%= form.number_field :number_of_plans_a2, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :number_of_plans_a3 %>
|
||||
<%= form.number_field :number_of_plans_a3, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="my-5">
|
||||
<%= form.label :costum_qm_plan %>
|
||||
<%= form.text_field :costum_qm_plan, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
||||
</div>
|
||||
|
||||
<div class="inline">
|
||||
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
|
||||
</div>
|
||||
<% end %>
|
||||
77
app/views/jobs/_job.html.erb
Normal file
77
app/views/jobs/_job.html.erb
Normal file
@@ -0,0 +1,77 @@
|
||||
<div id="<%= dom_id job %>">
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Operator:</strong>
|
||||
<%= job.operator_id_id %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Costumer:</strong>
|
||||
<%= job.costumer_id_id %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Operator firstname:</strong>
|
||||
<%= job.operator_firstname %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Operator lastname:</strong>
|
||||
<%= job.operator_lastname %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Costumer firstname:</strong>
|
||||
<%= job.costumer_firstname %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Costumer lastname:</strong>
|
||||
<%= job.costumer_lastname %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Paid:</strong>
|
||||
<%= job.paid %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Printed at:</strong>
|
||||
<%= job.printed_at %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Intern:</strong>
|
||||
<%= job.intern %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Cost center:</strong>
|
||||
<%= job.cost_center %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Number of plans a0:</strong>
|
||||
<%= job.number_of_plans_a0 %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Number of plans a1:</strong>
|
||||
<%= job.number_of_plans_a1 %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Number of plans a2:</strong>
|
||||
<%= job.number_of_plans_a2 %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Number of plans a3:</strong>
|
||||
<%= job.number_of_plans_a3 %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Costum qm plan:</strong>
|
||||
<%= job.costum_qm_plan %>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
2
app/views/jobs/_job.json.jbuilder
Normal file
2
app/views/jobs/_job.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.extract! job, :id, :operator_id_id, :costumer_id_id, :operator_firstname, :operator_lastname, :costumer_firstname, :costumer_lastname, :paid, :printed_at, :intern, :cost_center, :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan, :created_at, :updated_at
|
||||
json.url job_url(job, format: :json)
|
||||
8
app/views/jobs/edit.html.erb
Normal file
8
app/views/jobs/edit.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="mx-auto md:w-2/3 w-full">
|
||||
<h1 class="font-bold text-4xl">Editing job</h1>
|
||||
|
||||
<%= render "form", job: @job %>
|
||||
|
||||
<%= link_to "Show this job", @job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
<%= link_to "Back to jobs", jobs_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
</div>
|
||||
21
app/views/jobs/index.html.erb
Normal file
21
app/views/jobs/index.html.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
<div class="w-full">
|
||||
<% if notice.present? %>
|
||||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
|
||||
<% content_for :title, "Jobs" %>
|
||||
|
||||
<div class="flex justify-between items-center">
|
||||
<h1 class="font-bold text-4xl">Jobs</h1>
|
||||
<%= link_to "New job", new_job_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
|
||||
</div>
|
||||
|
||||
<div id="jobs" class="min-w-full">
|
||||
<% @jobs.each do |job| %>
|
||||
<%= render job %>
|
||||
<p>
|
||||
<%= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
1
app/views/jobs/index.json.jbuilder
Normal file
1
app/views/jobs/index.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.array! @jobs, partial: "jobs/job", as: :job
|
||||
7
app/views/jobs/new.html.erb
Normal file
7
app/views/jobs/new.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<div class="mx-auto md:w-2/3 w-full">
|
||||
<h1 class="font-bold text-4xl">New job</h1>
|
||||
|
||||
<%= render "form", job: @job %>
|
||||
|
||||
<%= link_to "Back to jobs", jobs_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
</div>
|
||||
15
app/views/jobs/show.html.erb
Normal file
15
app/views/jobs/show.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<div class="mx-auto md:w-2/3 w-full flex">
|
||||
<div class="mx-auto">
|
||||
<% if notice.present? %>
|
||||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
|
||||
<% end %>
|
||||
|
||||
<%= render @job %>
|
||||
|
||||
<%= link_to "Edit this job", edit_job_path(@job), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
<%= link_to "Back to jobs", jobs_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
||||
<div class="inline-block ml-2">
|
||||
<%= button_to "Destroy this job", @job, method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
1
app/views/jobs/show.json.jbuilder
Normal file
1
app/views/jobs/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! "jobs/job", job: @job
|
||||
Reference in New Issue
Block a user