diff --git a/app/controllers/participants_controller.rb b/app/controllers/participants_controller.rb new file mode 100644 index 0000000..cde1f19 --- /dev/null +++ b/app/controllers/participants_controller.rb @@ -0,0 +1,49 @@ +class ParticipantsController < ApplicationController + before_action :set_participant, only: [:show, :edit, :update, :destroy] + + def index + @participants = Participant.all + end + + def show + end + + def new + @participant = Participant.new + end + + def create + @participant = Participant.new(participant_params) + if @participant.save + redirect_to @participant, notice: 'Participant was successfully created.' + else + render :new + end + end + + def edit + end + + def update + if @participant.update(participant_params) + redirect_to @participant, notice: 'Participant was successfully updated.' + else + render :edit + end + end + + def destroy + @participant.destroy + redirect_to participants_url, notice: 'Participant was successfully destroyed.' + end + + private + def set_participant + @participant = Participant.find(params[:id]) + end + + def participant_params + params.require(:participant).permit(:name, :address, :phone, :email, :mci, :dob, :ssn, :gender, :employer_id) + end + end + \ No newline at end of file diff --git a/app/helpers/participants_helper.rb b/app/helpers/participants_helper.rb new file mode 100644 index 0000000..7059f83 --- /dev/null +++ b/app/helpers/participants_helper.rb @@ -0,0 +1,2 @@ +module ParticipantsHelper +end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index cd79d94..8f0b644 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -1,6 +1,3 @@ -// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "@hotwired/turbo-rails" import "controllers" -import Rails from '@rails/ujs'; -Rails.start(); diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5156112..634f723 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,40 +5,22 @@ Obdev - <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'rails-ujs', 'data-turbolinks-track': 'reload' %> <%= csrf_meta_tags %> + <%= javascript_importmap_tags %> + + - + - - - - <%= yield %> + <%= yield %>

<%= notice %>

<%= alert %>

- - - + <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> + diff --git a/app/views/participants/_form.html.erb b/app/views/participants/_form.html.erb new file mode 100644 index 0000000..236c3cb --- /dev/null +++ b/app/views/participants/_form.html.erb @@ -0,0 +1,148 @@ +<%= form_with(model: participant, local: true) do |form| %> + <% if participant.errors.any? %> +
+

<%= pluralize(participant.errors.count, "error") %> prohibited this participant 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 :mci, 'MCI' %> + <%= form.text_field :mci %> +
+ +
+ <%= form.label :dob, 'Date of Birth' %> + <%= form.date_field :dob %> +
+ +
+ <%= form.label :ssn, 'Social Security Number' %> + <%= form.text_field :ssn, id: 'ssn-field', maxlength: 11, placeholder: 'XXX-XX-XXXX' %> +
+ +
+ <%= form.label :gender %> + <%= form.select :gender, ['Unknown', 'Female', 'Male', 'Non-Binary', 'Other'] %> +
+ +
+ <%= form.submit %> +
+ <% end %> + + <%# This is to correct phone number entry %> + + + +<%# This is for auto resizing the address field %> + + +<%# This is to require 1 @ sign for email entry %> + + + +<%# This is for Social Security formatting and # of digits %> + + + + diff --git a/app/views/participants/edit.html.erb b/app/views/participants/edit.html.erb new file mode 100644 index 0000000..ede1fc9 --- /dev/null +++ b/app/views/participants/edit.html.erb @@ -0,0 +1,6 @@ +

Edit Participant

+ +<%= render 'form', participant: @participant %> + +<%= link_to 'Show', @participant %> | +<%= link_to 'Back to List', participants_path %> diff --git a/app/views/participants/index.html.erb b/app/views/participants/index.html.erb new file mode 100644 index 0000000..6fdab32 --- /dev/null +++ b/app/views/participants/index.html.erb @@ -0,0 +1,27 @@ +

Participants

+ + + + + + + + + + + + + <% @participants.each do |participant| %> + + + + + + + + + <% end %> + +
NameAddress
<%= participant.name %><%= participant.address %><%= link_to 'Show', participant %><%= link_to 'Edit', edit_participant_path(participant) %><%= link_to 'Destroy', participant, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +<%= link_to 'New Participant', new_participant_path %> diff --git a/app/views/participants/new.html.erb b/app/views/participants/new.html.erb new file mode 100644 index 0000000..c5aabe3 --- /dev/null +++ b/app/views/participants/new.html.erb @@ -0,0 +1,8 @@ +

New Participant

+ +<%= render 'form', participant: @participant %> + +<%= link_to 'Back to List', participants_path %> + + + diff --git a/app/views/participants/show.html.erb b/app/views/participants/show.html.erb new file mode 100644 index 0000000..3b86add --- /dev/null +++ b/app/views/participants/show.html.erb @@ -0,0 +1,16 @@ +

Participant Details

+ +

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

+ +

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

+ + + +<%= link_to 'Edit', edit_participant_path(@participant) %> | +<%= link_to 'Back to List', participants_path %> diff --git a/config/importmap.rb b/config/importmap.rb index bc060ed..df1d6d7 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -4,4 +4,5 @@ pin "application" pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true pin "@hotwired/stimulus", to: "stimulus.min.js" pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" +pin "auto_expand_textarea", to: "auto_expand_textarea.js" pin_all_from "app/javascript/controllers", under: "controllers" diff --git a/config/routes.rb b/config/routes.rb index 9db3805..b3eebb0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,8 @@ Rails.application.routes.draw do root to: 'devise/sessions#new' end + resources :participants + get 'home/index' diff --git a/test/controllers/participants_controller_test.rb b/test/controllers/participants_controller_test.rb new file mode 100644 index 0000000..d701223 --- /dev/null +++ b/test/controllers/participants_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ParticipantsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end