Sha256: 5eb9872f1c3da6ebacc46556ddc715500dc4d5d872472bad0076eb964bec21d3

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

module MrCommon
  module Registrations
    # Admin CRUD for Registrations.
    class RegistrationsController < BaseController
      def index
        @registrations = Registration.order(first_name: :asc, last_name: :asc)
      end

      def show
        @registration = Registration.find(params[:id])
      end

      def new
        @registration = Registration.new
      end

      def create
        @registration = Registration.new(registration_params)

        if @registration.save
          redirect_to registrations_path, notice: "Registration saved."
        else
          flash.now[:alert] = MrCommon.registration_failure_alert
          render :new, status: :unprocessable_entity
        end
      end

      def edit
        @registration = Registration.find(params[:id])
      end

      def update
        @registration = Registration.find(params[:id])

        if @registration.update(registration_params)
          redirect_to @registration, notice: "Registration saved."
        else
          flash.now[:alert] = MrCommon.registration_failure_alert
          render :new, status: :unprocessable_entity
        end
      end

      def destroy
        @registration = Registration.find(params[:id])

        if @registration.destroy
          redirect_to registrations_path, notice: "Registration destroyed."
        else
          redirect_to @registration, alert: "Unable to destroy Registration."
        end
      end

      private

        def registration_params
          params.require(
            :registration
          ).permit(
            :first_name,
            :last_name,
            :email,
            :company_name,
            :telephone,
            :job_title,
            :confirmed,
            :contact_via_email,
            :contact_via_phone,
          )
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mr_common-2.1.0 app/controllers/mr_common/registrations/registrations_controller.rb
mr_common-2.0.0 app/controllers/mr_common/registrations/registrations_controller.rb