Removed all entries for all models and changed Employer model to reflect first name and last name instead of Name
This commit is contained in:
parent
97bde74af0
commit
1656508ccd
|
@ -3,7 +3,7 @@ class EmployersController < ApplicationController
|
|||
|
||||
# GET /employers
|
||||
def index
|
||||
@employers = Employer.order(:name)
|
||||
@employers = Employer.order(:last_name)
|
||||
end
|
||||
|
||||
# GET /employers/:id
|
||||
|
|
|
@ -2,5 +2,10 @@ class Employer < ApplicationRecord
|
|||
has_many :participants
|
||||
has_many :workers, through: :participants
|
||||
# Association with Vendor if needed
|
||||
|
||||
def full_name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -11,8 +11,13 @@
|
|||
<% end %>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :name, class: 'form-label' %>
|
||||
<%= form.text_field :name, class: 'form-control' %>
|
||||
<%= form.label :first_name, class: 'form-label' %>
|
||||
<%= form.text_field :first_name, class: 'form-control' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :last_name, class: 'form-label' %>
|
||||
<%= form.text_field :last_name, class: 'form-control' %>
|
||||
</div>
|
||||
|
||||
<!-- Repeat for other attributes -->
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
<table class="table table-striped table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Address</th>
|
||||
<th>Phone</th>
|
||||
<th>Email</th>
|
||||
|
@ -21,7 +22,7 @@
|
|||
<tbody>
|
||||
<% @employers.each do |employer| %>
|
||||
<tr>
|
||||
<td><%= employer.name %></td>
|
||||
<td><%= employer.first_name %> <%= employer.last_name %></td>
|
||||
<td><%= employer.address %></td>
|
||||
<td><%= employer.phone %></td>
|
||||
<td><%= employer.email %></td>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
<strong>Name:</strong>
|
||||
<%= @employer.name %>
|
||||
<%= @employer.first_name %> <%= @employer.last_name %>
|
||||
</p>
|
||||
|
||||
<p class="card-text">
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class RenameNameInEmployers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
rename_column :employers, :name, :first_name
|
||||
add_column :employers, :last_name, :string
|
||||
end
|
||||
end
|
|
@ -10,9 +10,9 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_01_23_235419) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_01_30_033832) do
|
||||
create_table "employers", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "first_name"
|
||||
t.string "address"
|
||||
t.string "phone"
|
||||
t.string "email"
|
||||
|
@ -22,6 +22,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_23_235419) do
|
|||
t.string "gender"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "last_name"
|
||||
end
|
||||
|
||||
create_table "employers_vendors", id: false, force: :cascade do |t|
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
namespace :update do
|
||||
desc "Update employer names"
|
||||
task employer_names: :environment do
|
||||
Employer.find_each do |employer|
|
||||
names = employer.name.split
|
||||
employer.update(first_name: names.first, last_name: names.drop(1).join(' '))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue