|
| 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 |
0 commit comments