Successfully changed all of the Participant model to use First Name and Last Name except for Show where it combines them into the Name Field. Everything works.
This commit is contained in:
parent
02d8612409
commit
dad8abad3e
|
@ -67,12 +67,12 @@ class ParticipantsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def participant_params
|
def participant_params
|
||||||
params.require(:participant).permit(:name, :address, :phone, :email, :mci, :dob, :ssn, :gender, :employer_id)
|
params.require(:participant).permit(:first_name, :last_name, :address, :phone, :email, :mci, :dob, :ssn, :gender, :employer_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def employer_params_from_participant(participant)
|
def employer_params_from_participant(participant)
|
||||||
{
|
{
|
||||||
name: participant.name,
|
name: "#{participant.first_name} #{participant.last_name}",
|
||||||
address: participant.address,
|
address: participant.address,
|
||||||
phone: participant.phone,
|
phone: participant.phone,
|
||||||
email: participant.email,
|
email: participant.email,
|
||||||
|
@ -81,4 +81,5 @@ class ParticipantsController < ApplicationController
|
||||||
gender: participant.gender # Mapping Gender
|
gender: participant.gender # Mapping Gender
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,8 @@ class Participant < ApplicationRecord
|
||||||
# This makes the association to Employer optional
|
# This makes the association to Employer optional
|
||||||
belongs_to :employer, optional: true
|
belongs_to :employer, optional: true
|
||||||
belongs_to :worker, optional: true
|
belongs_to :worker, optional: true
|
||||||
|
validates :first_name, presence: true
|
||||||
|
validates :last_name, presence: true
|
||||||
|
|
||||||
# Other associations
|
# Other associations
|
||||||
has_and_belongs_to_many :programs
|
has_and_belongs_to_many :programs
|
||||||
|
|
|
@ -11,10 +11,16 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<%= form.label :name, class: 'form-label' %>
|
<%= form.label :first_name, 'First Name', class: 'form-label' %>
|
||||||
<%= form.text_field :name, class: 'form-control' %>
|
<%= form.text_field :first_name, class: 'form-control' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<%= form.label :last_name, 'Last Name', class: 'form-label' %>
|
||||||
|
<%= form.text_field :last_name, class: 'form-control' %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<%= form.label :address, class: 'form-label' %>
|
<%= form.label :address, class: 'form-label' %>
|
||||||
<%= form.text_area :address, rows: 1, class: 'form-control auto-expand' %>
|
<%= form.text_area :address, rows: 1, class: 'form-control auto-expand' %>
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
<table class="table table-striped table-hover">
|
<table class="table table-striped table-hover">
|
||||||
<thead class="table-dark">
|
<thead class="table-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>First Name</th>
|
||||||
|
<th>Last Name</th>
|
||||||
<th>Address</th>
|
<th>Address</th>
|
||||||
<th>Phone</th>
|
<th>Phone</th>
|
||||||
<th>Email</th>
|
<th>Email</th>
|
||||||
|
@ -19,7 +20,8 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @participants.each do |participant| %>
|
<% @participants.each do |participant| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= participant.name %></td>
|
<td><%= participant.first_name %></td>
|
||||||
|
<td><%= participant.last_name %></td>
|
||||||
<td><%= participant.address %></td>
|
<td><%= participant.address %></td>
|
||||||
<td><%= participant.phone %></td>
|
<td><%= participant.phone %></td>
|
||||||
<td><%= participant.email %></td>
|
<td><%= participant.email %></td>
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="card-text">
|
<p class="card-text">
|
||||||
<strong>Name:</strong>
|
<strong>Name:</strong>
|
||||||
<%= @participant.name %>
|
<%= @participant.first_name %> <%= @participant.last_name %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="card-text">
|
<p class="card-text">
|
||||||
<strong>Address:</strong>
|
<strong>Address:</strong>
|
||||||
<%= @participant.address %>
|
<%= @participant.address %>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class RenameNameToFirstNameAndAddLastNameToParticipants < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
rename_column :participants, :name, :first_name
|
||||||
|
add_column :participants, :last_name, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_01_20_051441) do
|
ActiveRecord::Schema[7.1].define(version: 2024_01_20_060936) do
|
||||||
create_table "employers", force: :cascade do |t|
|
create_table "employers", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "address"
|
t.string "address"
|
||||||
|
@ -30,7 +30,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_20_051441) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "participants", force: :cascade do |t|
|
create_table "participants", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "first_name"
|
||||||
t.string "address"
|
t.string "address"
|
||||||
t.string "phone"
|
t.string "phone"
|
||||||
t.string "email"
|
t.string "email"
|
||||||
|
@ -42,6 +42,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_20_051441) do
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "worker_id"
|
t.integer "worker_id"
|
||||||
|
t.string "last_name"
|
||||||
t.index ["employer_id"], name: "index_participants_on_employer_id"
|
t.index ["employer_id"], name: "index_participants_on_employer_id"
|
||||||
t.index ["worker_id"], name: "index_participants_on_worker_id"
|
t.index ["worker_id"], name: "index_participants_on_worker_id"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue