Added user model and fixed reference in migration
This commit is contained in:
@@ -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]
|
||||
|
||||
# GET /jobs or /jobs.json
|
||||
def index
|
||||
@@ -7,8 +7,7 @@ class JobsController < ApplicationController
|
||||
end
|
||||
|
||||
# GET /jobs/1 or /jobs/1.json
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
# GET /jobs/new
|
||||
def new
|
||||
@@ -16,8 +15,7 @@ class JobsController < ApplicationController
|
||||
end
|
||||
|
||||
# GET /jobs/1/edit
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
# POST /jobs or /jobs.json
|
||||
def create
|
||||
@@ -25,7 +23,7 @@ class JobsController < ApplicationController
|
||||
|
||||
respond_to do |format|
|
||||
if @job.save
|
||||
format.html { redirect_to job_url(@job), notice: "Job was successfully created." }
|
||||
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 }
|
||||
@@ -38,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 job_url(@job), notice: 'Job was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @job }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
@@ -52,19 +50,21 @@ class JobsController < ApplicationController
|
||||
@job.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to jobs_url, notice: "Job was successfully destroyed." }
|
||||
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
|
||||
# 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, :costumer_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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Job < ApplicationRecord
|
||||
belongs_to :operator_id
|
||||
belongs_to :costumer_id
|
||||
belongs_to :operator, class_name: 'User', optional: true
|
||||
belongs_to :costumer, class_name: 'User', optional: true
|
||||
end
|
||||
|
||||
3
app/models/user.rb
Normal file
3
app/models/user.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class User < ApplicationRecord
|
||||
has_many :Jobs, foreign_key: :costumer_id
|
||||
end
|
||||
@@ -1,7 +1,11 @@
|
||||
<%= 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>
|
||||
<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| %>
|
||||
@@ -11,44 +15,18 @@
|
||||
</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" %>
|
||||
<%= 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" %>
|
||||
<%= 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">
|
||||
@@ -58,35 +36,41 @@
|
||||
|
||||
<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" %>
|
||||
<%= 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" %>
|
||||
<%= 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" %>
|
||||
<%= 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" %>
|
||||
<%= 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" %>
|
||||
<%= 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="inline">
|
||||
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
|
||||
<%= form.submit class:
|
||||
"rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<div id="<%= dom_id job %>">
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Operator:</strong>
|
||||
<%= job.operator_id_id %>
|
||||
<%= job.operator_id %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
<strong class="block font-medium mb-1">Costumer:</strong>
|
||||
<%= job.costumer_id_id %>
|
||||
<%= job.costumer_id %>
|
||||
</p>
|
||||
|
||||
<p class="my-5">
|
||||
|
||||
@@ -1,2 +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.extract! job, :id, :operator_id, :costumer_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)
|
||||
|
||||
Reference in New Issue
Block a user