From 9569ae50c6294fd6559ef25b91fa2eef6adeba52 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 17 Jan 2024 01:44:36 -0600 Subject: [PATCH] All associated Part, Emp, Worker and Vendor pages have been created (still need to edit look and recheck field validation and input) --- app/controllers/vendors_controller.rb | 47 +++++++++++ app/helpers/vendors_helper.rb | 2 + app/views/vendors/_form.html.erb | 94 +++++++++++++++++++++ app/views/vendors/edit.html.erb | 6 ++ app/views/vendors/index.html.erb | 36 ++++++++ app/views/vendors/new.html.erb | 5 ++ app/views/vendors/show.html.erb | 33 ++++++++ config/routes.rb | 2 +- test/controllers/vendors_controller_test.rb | 7 ++ 9 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 app/controllers/vendors_controller.rb create mode 100644 app/helpers/vendors_helper.rb create mode 100644 app/views/vendors/_form.html.erb create mode 100644 app/views/vendors/edit.html.erb create mode 100644 app/views/vendors/index.html.erb create mode 100644 app/views/vendors/new.html.erb create mode 100644 app/views/vendors/show.html.erb create mode 100644 test/controllers/vendors_controller_test.rb diff --git a/app/controllers/vendors_controller.rb b/app/controllers/vendors_controller.rb new file mode 100644 index 0000000..33e83ed --- /dev/null +++ b/app/controllers/vendors_controller.rb @@ -0,0 +1,47 @@ +class VendorsController < ApplicationController + def index + @vendors = Vendor.all + end + + def show + @vendor = Vendor.find(params[:id]) + end + + def new + @vendor = Vendor.new + end + + def create + @vendor = Vendor.new(vendor_params) + if @vendor.save + redirect_to @vendor + else + render :new + end + end + + def edit + @vendor = Vendor.find(params[:id]) + end + + def update + @vendor = Vendor.find(params[:id]) + if @vendor.update(vendor_params) + redirect_to @vendor + else + render :edit + end + end + + def destroy + @vendor = Vendor.find(params[:id]) + @vendor.destroy + redirect_to vendors_path + end + + private + def vendor_params + params.require(:vendor).permit(:name, :address, :phone, :email, :dba, :tin, :contact) + end + end + \ No newline at end of file diff --git a/app/helpers/vendors_helper.rb b/app/helpers/vendors_helper.rb new file mode 100644 index 0000000..5429ffa --- /dev/null +++ b/app/helpers/vendors_helper.rb @@ -0,0 +1,2 @@ +module VendorsHelper +end diff --git a/app/views/vendors/_form.html.erb b/app/views/vendors/_form.html.erb new file mode 100644 index 0000000..48a1ae6 --- /dev/null +++ b/app/views/vendors/_form.html.erb @@ -0,0 +1,94 @@ +<%= form_with(model: vendor, local: true) do |form| %> + <% if vendor.errors.any? %> +
+

<%= pluralize(vendor.errors.count, "error") %> prohibited this vendor from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :address %> + <%= form.text_area :address, rows: 1, class: 'auto-expand' %> +
+ +
+ <%= form.label :phone %> + <%= form.telephone_field :phone, id: 'phone-field' %> +
+ +
+ <%= form.label :email %> + <%= form.email_field :email, id: 'email-field', required: true %> +
+ +
+ <%= form.label :dba, 'DBA' %> + <%= form.text_field :dba %> +
+ +
+ <%= form.label :tin, 'TIN' %> + <%= form.text_field :tin, maxlength: 9 %> +
+ +
+ <%= form.label :contact %> + <%= form.text_field :contact %> +
+ +
+ <%= form.submit %> +
+ <% end %> + + + <%# This is to correct phone number entry %> + + +<%# This is for auto resizing the address field %> + \ No newline at end of file diff --git a/app/views/vendors/edit.html.erb b/app/views/vendors/edit.html.erb new file mode 100644 index 0000000..56876bc --- /dev/null +++ b/app/views/vendors/edit.html.erb @@ -0,0 +1,6 @@ +

Edit Vendor

+ +<%= render 'form', vendor: @vendor %> + +<%= link_to 'Cancel', vendor_path(@vendor) %> | +<%= link_to 'Back to List', vendors_path %> diff --git a/app/views/vendors/index.html.erb b/app/views/vendors/index.html.erb new file mode 100644 index 0000000..b222308 --- /dev/null +++ b/app/views/vendors/index.html.erb @@ -0,0 +1,36 @@ +

Vendors

+ + + + + + + + + + + + + + + + <% @vendors.each do |vendor| %> + + + + + + + + + + + <% end %> + +
NameAddressPhoneEmailDBATINContactActions
<%= vendor.name %><%= vendor.address %><%= vendor.phone %><%= vendor.email %><%= vendor.dba %><%= vendor.tin %><%= vendor.contact %> + <%= link_to 'Show', vendor_path(vendor) %> | + <%= link_to 'Edit', edit_vendor_path(vendor) %> | + <%= link_to 'Destroy', vendor_path(vendor), method: :delete, data: { confirm: 'Are you sure?' } %> +
+ +<%= link_to 'New Vendor', new_vendor_path %> diff --git a/app/views/vendors/new.html.erb b/app/views/vendors/new.html.erb new file mode 100644 index 0000000..e21f34c --- /dev/null +++ b/app/views/vendors/new.html.erb @@ -0,0 +1,5 @@ +

New Vendor

+ +<%= render 'form', vendor: @vendor %> + +<%= link_to 'Back to List', vendors_path %> diff --git a/app/views/vendors/show.html.erb b/app/views/vendors/show.html.erb new file mode 100644 index 0000000..6fdd764 --- /dev/null +++ b/app/views/vendors/show.html.erb @@ -0,0 +1,33 @@ +

Vendor Details

+ +

+ Name: + <%= @vendor.name %> +

+

+ Address: + <%= @vendor.address %> +

+

+ Phone: + <%= @vendor.phone %> +

+

+ Email: + <%= @vendor.email %> +

+

+ DBA: + <%= @vendor.dba %> +

+

+ TIN: + <%= @vendor.tin %> +

+

+ Contact: + <%= @vendor.contact %> +

+ +<%= link_to 'Edit', edit_vendor_path(@vendor) %> | +<%= link_to 'Back to List', vendors_path %> diff --git a/config/routes.rb b/config/routes.rb index f77262c..9852521 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ Rails.application.routes.draw do resources :participants resources :employers resources :workers - + resources :vendors diff --git a/test/controllers/vendors_controller_test.rb b/test/controllers/vendors_controller_test.rb new file mode 100644 index 0000000..bbdefdf --- /dev/null +++ b/test/controllers/vendors_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class VendorsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end