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)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class CreateJobs < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :jobs do |t|
|
||||
t.references :operator_id, null: false, foreign_key: true
|
||||
t.references :costumer_id, null: false, foreign_key: true
|
||||
t.references :operator, null: true
|
||||
t.references :costumer, null: true
|
||||
t.string :operator_firstname
|
||||
t.string :operator_lastname
|
||||
t.string :costumer_firstname
|
||||
|
||||
13
db/migrate/20240730214152_create_users.rb
Normal file
13
db/migrate/20240730214152_create_users.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :users do |t|
|
||||
t.string :firstname
|
||||
t.string :lastname
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_foreign_key :jobs, :users, column: :operator_id
|
||||
add_foreign_key :jobs, :users, column: :costumer_id
|
||||
end
|
||||
end
|
||||
21
db/schema.rb
generated
21
db/schema.rb
generated
@@ -10,10 +10,10 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_07_27_101347) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_07_30_214152) do
|
||||
create_table "jobs", force: :cascade do |t|
|
||||
t.integer "operator_id_id", null: false
|
||||
t.integer "costumer_id_id", null: false
|
||||
t.integer "operator_id"
|
||||
t.integer "costumer_id"
|
||||
t.string "operator_firstname"
|
||||
t.string "operator_lastname"
|
||||
t.string "costumer_firstname"
|
||||
@@ -29,10 +29,17 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_27_101347) do
|
||||
t.float "costum_qm_plan"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["costumer_id_id"], name: "index_jobs_on_costumer_id_id"
|
||||
t.index ["operator_id_id"], name: "index_jobs_on_operator_id_id"
|
||||
t.index ["costumer_id"], name: "index_jobs_on_costumer_id"
|
||||
t.index ["operator_id"], name: "index_jobs_on_operator_id"
|
||||
end
|
||||
|
||||
add_foreign_key "jobs", "costumer_ids"
|
||||
add_foreign_key "jobs", "operator_ids"
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "firstname"
|
||||
t.string "lastname"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_foreign_key "jobs", "users", column: "costumer_id"
|
||||
add_foreign_key "jobs", "users", column: "operator_id"
|
||||
end
|
||||
|
||||
9
test/fixtures/users.yml
vendored
Normal file
9
test/fixtures/users.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
firstname: MyString
|
||||
lastname: MyString
|
||||
|
||||
two:
|
||||
firstname: MyString
|
||||
lastname: MyString
|
||||
7
test/models/user_test.rb
Normal file
7
test/models/user_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user