Skip to content

Commit 573c3bd

Browse files
committed
Create Facilitator model and basic Facilitator CRUD
1 parent 636fc7a commit 573c3bd

19 files changed

+285
-1
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
class FacilitatorsController < ApplicationController
2+
# Skip login requirement for new facilitator form
3+
# temporarily skipping authentication for all actions for development ease
4+
#TODO: remove :index & :show from skip_before_action
5+
if Rails.env.development?
6+
skip_before_action :authenticate_user!, only: [:index, :show, :update, :edit, :new, :create]
7+
end
8+
9+
before_action :set_facilitator, only: %i[ show edit update destroy ]
10+
11+
def index
12+
@facilitators = Facilitator.all
13+
end
14+
15+
def show
16+
@facilitator = Facilitator.find(params[:id])
17+
end
18+
19+
def new
20+
@facilitator = Facilitator.new
21+
end
22+
23+
def edit
24+
end
25+
26+
def create
27+
@facilitator = Facilitator.new(facilitator_params)
28+
29+
respond_to do |format|
30+
if @facilitator.save
31+
format.html { redirect_to @facilitator, notice: "Facilitator was successfully created." }
32+
else
33+
format.html { render :new, status: :unprocessable_entity }
34+
end
35+
end
36+
end
37+
38+
def update
39+
respond_to do |format|
40+
if @facilitator.update(facilitator_params)
41+
format.html { redirect_to @facilitator, notice: "Facilitator was successfully updated." }
42+
else
43+
format.html { render :edit, status: :unprocessable_entity }
44+
end
45+
end
46+
end
47+
48+
def destroy
49+
@facilitator.destroy
50+
51+
respond_to do |format|
52+
format.html { redirect_to facilitators_path, status: :see_other, notice: "Facilitator was successfully destroyed." }
53+
end
54+
end
55+
56+
private
57+
# Use callbacks to share common setup or constraints between actions.
58+
def set_facilitator
59+
@facilitator = Facilitator.find(params[:id])
60+
end
61+
62+
# Only allow a list of trusted parameters through.
63+
def facilitator_params
64+
params.require(:facilitator).permit(:first_name, :last_name, :email)
65+
end
66+
end

app/models/facilitator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Facilitator < ApplicationRecord
2+
has_one :user
3+
4+
validates :first_name, presence: true
5+
validates :last_name, presence: true
6+
validates :email, presence: true
7+
end

app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class User < ApplicationRecord
1515
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\z/
1616

1717
# Associations
18+
belongs_to :facilitator, optional: true
1819
has_many :workshops
1920

2021
# has_many :curriculum_workshops, -> (user) { }, class_name: 'Workshop'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%= form_for(@facilitator) do |f| %>
2+
<%= render 'shared/errors', resource: facilitator if facilitator.errors.any? %>
3+
4+
<div class="form-inputs">
5+
<%= f.label :first_name, class: 'bold' %>
6+
<%= f.text_field :first_name %>
7+
<%= f.label :last_name, class: 'bold' %>
8+
<%= f.text_field :last_name %>
9+
<%= f.label :email, class: 'bold' %>
10+
<%= f.text_field :email %>
11+
</div>
12+
13+
<div class="form-actions">
14+
<%= f.button :submit %>
15+
</div>
16+
<% end %>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1>Edit Facilitator</h1>
2+
3+
<%= render 'form', facilitator: @facilitator %>
4+
5+
<%= link_to 'Show', @facilitator %> |
6+
<%= link_to 'Back', facilitators_path %>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<p id="notice"><%= notice %></p>
2+
3+
<h1>Facilitators</h1>
4+
5+
<table>
6+
<thead>
7+
<tr>
8+
<th>First name</th>
9+
<th>Last name</th>
10+
<th>Email</th>
11+
<th colspan="3"></th>
12+
</tr>
13+
</thead>
14+
15+
<tbody>
16+
<% @facilitators.each do |facilitator| %>
17+
<tr>
18+
<td><%= facilitator.first_name %></td>
19+
<td><%= facilitator.last_name %></td>
20+
<td><%= facilitator.email %></td>
21+
<td><%= link_to 'Show', facilitator %></td>
22+
<td><%= link_to 'Edit', edit_facilitator_path(facilitator) %></td>
23+
<td><%= link_to 'Destroy', facilitator, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24+
</tr>
25+
<% end %>
26+
</tbody>
27+
</table>
28+
29+
<br>
30+
31+
<%= link_to 'New Facilitator', new_facilitator_path %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h1>New Facilitator</h1>
2+
3+
<%= render 'form', facilitator: @facilitator %>
4+
5+
<%= link_to 'Back', facilitators_path %>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<p id="notice"><%= notice %></p>
2+
3+
<p>
4+
<strong>First name:</strong>
5+
<%= @facilitator.first_name %>
6+
</p>
7+
8+
<p>
9+
<strong>Last name:</strong>
10+
<%= @facilitator.last_name %>
11+
</p>
12+
13+
<p>
14+
<strong>Email:</strong>
15+
<%= @facilitator.email %>
16+
</p>
17+
18+
<%= link_to 'Edit', edit_facilitator_path(@facilitator) %> |
19+
<%= link_to 'Back', facilitators_path %>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
resources :users
5353
resources :user_forms
54+
resources :facilitators
5455

5556
get 'reports/:id/edit_story', to: 'reports#edit_story', as: 'reports_edit_story'
5657
put 'reports/update_story/:id', to: 'reports#update_story', as: 'reports_update_story'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CreateFacilitators < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :facilitators do |t|
4+
t.string :first_name, null: false
5+
t.string :last_name, null: false
6+
t.string :email, null: false
7+
8+
t.timestamps
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)