All associated Worker pages have been created (need to edit fields and look)
This commit is contained in:
parent
d9873c0672
commit
d4f7e64906
|
@ -0,0 +1,59 @@
|
|||
class EmployersController < ApplicationController
|
||||
before_action :set_employer, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /employers
|
||||
def index
|
||||
@employers = Employer.all
|
||||
end
|
||||
|
||||
# GET /employers/:id
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /employers/new
|
||||
def new
|
||||
@employer = Employer.new
|
||||
end
|
||||
|
||||
# POST /employers
|
||||
def create
|
||||
@employer = Employer.new(employer_params)
|
||||
if @employer.save
|
||||
redirect_to @employer, notice: 'Employer was successfully created.'
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
# GET /employers/:id/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# PATCH/PUT /employers/:id
|
||||
def update
|
||||
if @employer.update(employer_params)
|
||||
redirect_to @employer, notice: 'Employer was successfully updated.'
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /employers/:id
|
||||
def destroy
|
||||
@employer = Employer.find(params[:id])
|
||||
@employer.destroy
|
||||
redirect_to employers_url, notice: 'Employer was successfully destroyed.'
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_employer
|
||||
@employer = Employer.find(params[:id])
|
||||
end
|
||||
|
||||
def employer_params
|
||||
params.require(:employer).permit(:name, :address, :phone, :email, :tin, :dob, :ssn, :gender)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
class WorkersController < ApplicationController
|
||||
def index
|
||||
@workers = Worker.all
|
||||
end
|
||||
|
||||
def show
|
||||
@worker = Worker.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@worker = Worker.new
|
||||
end
|
||||
|
||||
def create
|
||||
@worker = Worker.new(worker_params)
|
||||
if @worker.save
|
||||
redirect_to @worker
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@worker = Worker.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@worker = Worker.find(params[:id])
|
||||
if @worker.update(worker_params)
|
||||
redirect_to @worker
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@worker = Worker.find(params[:id])
|
||||
@worker.destroy
|
||||
redirect_to workers_path
|
||||
end
|
||||
|
||||
private
|
||||
def worker_params
|
||||
params.require(:worker).permit(:name, :address, :phone, :email, :dob, :ssn, :gender)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module EmployersHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module WorkersHelper
|
||||
end
|
|
@ -1,3 +1,5 @@
|
|||
import "@hotwired/turbo-rails"
|
||||
import "controllers"
|
||||
import Rails from "@rails/ujs";
|
||||
import "@hotwired/turbo-rails";
|
||||
import "controllers";
|
||||
|
||||
Rails.start();
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<%= form_with(model: employer, local: true) do |form| %>
|
||||
<% if employer.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(employer.errors.count, "error") %> prohibited this employer from being saved:</h2>
|
||||
<ul>
|
||||
<% employer.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :name %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<!-- Repeat for other attributes -->
|
||||
<div class="field">
|
||||
<%= form.label :address %>
|
||||
<%= form.text_area :address, rows: 1, class: 'auto-expand' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :phone %>
|
||||
<%= form.telephone_field :phone, id: 'phone-field' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email, id: 'email-field', required: true %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :tin, 'TIN' %>
|
||||
<%= form.text_field :tin, maxlength: 9 %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :dob, 'Date of Birth' %>
|
||||
<%= form.date_field :dob %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :ssn, 'Social Security Number' %>
|
||||
<%= form.text_field :ssn, id: 'ssn-field', maxlength: 11, placeholder: 'XXX-XX-XXXX' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :gender %>
|
||||
<%= form.select :gender, ['Unknown', 'Female', 'Male', 'Non-Binary', 'Other'] %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<%# This is to correct phone number entry %>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const phoneField = document.getElementById('phone-field');
|
||||
|
||||
phoneField.addEventListener('input', function() {
|
||||
let input = phoneField.value.replace(/\D/g, ''); // Remove non-numeric characters
|
||||
const inputLength = input.length;
|
||||
|
||||
if (inputLength > 3 && inputLength <= 6) {
|
||||
input = `(${input.slice(0, 3)}) ${input.slice(3)}`;
|
||||
} else if (inputLength > 6) {
|
||||
input = `(${input.slice(0, 3)}) ${input.slice(3, 6)}-${input.slice(6, 10)}`;
|
||||
}
|
||||
|
||||
phoneField.value = input;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<%# This is for auto resizing the address field %>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const textareas = document.querySelectorAll('.auto-expand');
|
||||
|
||||
const resizeTextarea = function(el) {
|
||||
el.style.height = 'auto';
|
||||
el.style.height = (el.scrollHeight) + 'px';
|
||||
}
|
||||
|
||||
textareas.forEach(textarea => {
|
||||
textarea.addEventListener('input', function() {
|
||||
resizeTextarea(textarea);
|
||||
});
|
||||
|
||||
// Initial resize
|
||||
resizeTextarea(textarea);
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,10 @@
|
|||
<h1>Edit Employer</h1>
|
||||
|
||||
<%= render 'form', employer: @employer %>
|
||||
|
||||
<%= link_to 'Show', @employer %> |
|
||||
<%= link_to 'Back to List', employers_path %>
|
||||
<%= link_to 'Destroy', @employer, method: :delete, data: { confirm: 'Are you sure?', turbo: 'false' } %>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<h1>Employers</h1>
|
||||
|
||||
<%= link_to 'New Employer', new_employer_path %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>Phone</th>
|
||||
<th>Email</th>
|
||||
<th>TIN</th>
|
||||
<th>DOB</th>
|
||||
<th>SSN</th>
|
||||
<th>Gender</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @employers.each do |employer| %>
|
||||
<tr>
|
||||
<td><%= employer.name %></td>
|
||||
<td><%= employer.address %></td>
|
||||
<td><%= employer.phone %></td>
|
||||
<td><%= employer.email %></td>
|
||||
<td><%= employer.tin %></td>
|
||||
<td><%= employer.dob %></td>
|
||||
<td><%= employer.ssn %></td>
|
||||
<td><%= employer.gender %></td>
|
||||
<td>
|
||||
<%= link_to 'Show', employer %>
|
||||
<%= link_to 'Edit', edit_employer_path(employer) %>
|
||||
<%= link_to 'Destroy', @employer, method: :delete, data: { confirm: 'Are you sure?', turbo: 'false' } %>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
|
@ -0,0 +1,5 @@
|
|||
<h1>New Employer</h1>
|
||||
|
||||
<%= render 'form', employer: @employer %>
|
||||
|
||||
<%= link_to 'Back to List', employers_path %>
|
|
@ -0,0 +1,48 @@
|
|||
<h1>Employer Details</h1>
|
||||
|
||||
<p>
|
||||
<strong>Name:</strong>
|
||||
<%= @employer.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Address:</strong>
|
||||
<%= @employer.address %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Phone:</strong>
|
||||
<%= @employer.phone %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Email:</strong>
|
||||
<%= @employer.email %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>TIN:</strong>
|
||||
<%= @employer.tin %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Date of Birth:</strong>
|
||||
<%= @employer.dob %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>SSN:</strong>
|
||||
<%= @employer.ssn %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Gender:</strong>
|
||||
<%= @employer.gender %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_employer_path(@employer) %> |
|
||||
<%= link_to 'Back to List', employers_path %>
|
||||
<%= link_to 'Destroy', @employer, method: :delete, data: { confirm: 'Are you sure?', turbo: 'false' } %>
|
||||
|
||||
|
||||
|
|
@ -30,7 +30,6 @@
|
|||
<div class="field">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email, id: 'email-field', required: true %>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -121,28 +120,7 @@
|
|||
|
||||
|
||||
<%# This is for Social Security formatting and # of digits %>
|
||||
<script>
|
||||
document.addEventListener('turbolinks:load', function() {
|
||||
const ssnField = document.getElementById('ssn-field');
|
||||
|
||||
ssnField.addEventListener('input', function(event) {
|
||||
let input = event.target.value.replace(/\D/g, ''); // Remove non-numeric characters
|
||||
if (input.length > 9) {
|
||||
input = input.substring(0, 9); // Limit to 9 digits
|
||||
}
|
||||
|
||||
let formattedSSN = '';
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (i === 3 || i === 5) {
|
||||
formattedSSN += '-';
|
||||
}
|
||||
formattedSSN += input[i];
|
||||
}
|
||||
|
||||
event.target.value = formattedSSN;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
<%= form_with(model: worker, local: true) do |form| %>
|
||||
<% if worker.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(worker.errors.count, "error") %> prohibited this worker from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% worker.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :name %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :address %>
|
||||
<%= form.text_area :address, rows: 1, class: 'auto-expand' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :phone %>
|
||||
<%= form.telephone_field :phone, id: 'phone-field' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email, id: 'email-field', required: true %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :dob %>
|
||||
<%= form.date_field :dob %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :ssn, 'Social Security Number' %>
|
||||
<%= form.text_field :ssn, id: 'ssn-field', maxlength: 11, placeholder: 'XXX-XX-XXXX' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :gender %>
|
||||
<%= form.select :gender, ['Unknown', 'Female', 'Male', 'Non-Binary', 'Other'] %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<%# This is to correct phone number entry %>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const phoneField = document.getElementById('phone-field');
|
||||
|
||||
phoneField.addEventListener('input', function() {
|
||||
let input = phoneField.value.replace(/\D/g, ''); // Remove non-numeric characters
|
||||
const inputLength = input.length;
|
||||
|
||||
if (inputLength > 3 && inputLength <= 6) {
|
||||
input = `(${input.slice(0, 3)}) ${input.slice(3)}`;
|
||||
} else if (inputLength > 6) {
|
||||
input = `(${input.slice(0, 3)}) ${input.slice(3, 6)}-${input.slice(6, 10)}`;
|
||||
}
|
||||
|
||||
phoneField.value = input;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<%# This is for auto resizing the address field %>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const textareas = document.querySelectorAll('.auto-expand');
|
||||
|
||||
const resizeTextarea = function(el) {
|
||||
el.style.height = 'auto';
|
||||
el.style.height = (el.scrollHeight) + 'px';
|
||||
}
|
||||
|
||||
textareas.forEach(textarea => {
|
||||
textarea.addEventListener('input', function() {
|
||||
resizeTextarea(textarea);
|
||||
});
|
||||
|
||||
// Initial resize
|
||||
resizeTextarea(textarea);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<%# This is to require 1 @ sign for email entry %>
|
||||
<script>
|
||||
document.addEventListener('turbolinks:load', function() {
|
||||
const emailField = document.getElementById('email-field');
|
||||
|
||||
emailField.addEventListener('input', function() {
|
||||
const emailValue = emailField.value;
|
||||
const atSignCount = (emailValue.match(/@/g) || []).length;
|
||||
|
||||
if (atSignCount !== 1) {
|
||||
emailField.setCustomValidity("Email must contain exactly one '@' sign.");
|
||||
} else {
|
||||
emailField.setCustomValidity('');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<%# This is for Social Security formatting and # of digits %>
|
|
@ -0,0 +1,6 @@
|
|||
<h1>Edit Worker</h1>
|
||||
|
||||
<%= render 'form', worker: @worker %>
|
||||
|
||||
<%= link_to 'Cancel', worker_path(@worker) %> |
|
||||
<%= link_to 'Back to List', workers_path %>
|
|
@ -0,0 +1,36 @@
|
|||
<h1>Workers</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>Phone</th>
|
||||
<th>Email</th>
|
||||
<th>DOB</th>
|
||||
<th>SSN</th>
|
||||
<th>Gender</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @workers.each do |worker| %>
|
||||
<tr>
|
||||
<td><%= worker.name %></td>
|
||||
<td><%= worker.address %></td>
|
||||
<td><%= worker.phone %></td>
|
||||
<td><%= worker.email %></td>
|
||||
<td><%= worker.dob %></td>
|
||||
<td><%= worker.ssn %></td>
|
||||
<td><%= worker.gender %></td>
|
||||
<td>
|
||||
<%= link_to 'Show', worker_path(worker) %> |
|
||||
<%= link_to 'Edit', edit_worker_path(worker) %> |
|
||||
<%= link_to 'Destroy', worker_path(worker), method: :delete, data: { confirm: 'Are you sure?' } %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= link_to 'New Worker', new_worker_path %>
|
|
@ -0,0 +1,5 @@
|
|||
<h1>New Worker</h1>
|
||||
|
||||
<%= render 'form', worker: @worker %>
|
||||
|
||||
<%= link_to 'Back to List', workers_path %>
|
|
@ -0,0 +1,33 @@
|
|||
<h1>Worker Details</h1>
|
||||
|
||||
<p>
|
||||
<strong>Name:</strong>
|
||||
<%= @worker.name %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Address:</strong>
|
||||
<%= @worker.address %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Phone:</strong>
|
||||
<%= @worker.phone %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Email:</strong>
|
||||
<%= @worker.email %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>DOB:</strong>
|
||||
<%= @worker.dob %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>SSN:</strong>
|
||||
<%= @worker.ssn %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Gender:</strong>
|
||||
<%= @worker.gender %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_worker_path(@worker) %> |
|
||||
<%= link_to 'Back to List', workers_path %>
|
|
@ -10,6 +10,9 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :participants
|
||||
resources :employers
|
||||
resources :workers
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class EmployersControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class WorkersControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue