Sha256: 5112124ae4996964ed94d4108b6fdd1d1e30141d95239a0ff41a7927dcf20904

Contents?: true

Size: 1.66 KB

Versions: 140

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/events"

module Renalware
  module Events
    class TypesController < BaseController
      def new
        event_type = Type.new
        authorize event_type
        render locals: { event_type: event_type }
      end

      def create
        event_type = Type.new(event_params)
        authorize event_type
        if event_type.save
          redirect_to events_types_path, notice: success_msg_for("event type")
        else
          flash.now[:error] = failed_msg_for("event type")
          render :new, locals: { event_type: event_type }
        end
      end

      def index
        event_types = Type.all
        authorize event_types
        render locals: { event_types: event_types }
      end

      def edit
        event_type = load_and_authorize_event_type
        render locals: { event_type: event_type }
      end

      def update
        event_type = load_and_authorize_event_type
        if event_type.update(event_params)
          redirect_to events_types_path, notice: success_msg_for("event type")
        else
          flash.now[:error] = failed_msg_for("event type")
          render :edit, locals: { event_type: event_type }
        end
      end

      def destroy
        event_type = load_and_authorize_event_type
        event_type.destroy
        redirect_to events_types_path, notice: success_msg_for("event type")
      end

      private

      def event_params
        params.require(:events_type).permit(:name, :deleted_at)
      end

      def load_and_authorize_event_type
        event_type = Type.find(params[:id])
        authorize event_type
        event_type
      end
    end
  end
end

Version data entries

140 entries across 140 versions & 1 rubygems

Version Path
renalware-core-2.0.167 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.166 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.165 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.164 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.163 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.162 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.161 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.160 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.159 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.158 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.157 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.156 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.155 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.153 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.152 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.151 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.149 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.148 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.147 app/controllers/renalware/events/types_controller.rb
renalware-core-2.0.146 app/controllers/renalware/events/types_controller.rb