Sha256: 77104c1ee058c6f071e3fd7f5fbcd420e6ff5665b15abc990379effa1c2acbdc

Contents?: true

Size: 1.5 KB

Versions: 134

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Renalware
  module System
    class MessagesController < BaseController
      def index
        messages = Message.all.order(created_at: :desc)
        authorize messages
        render locals: { messages: messages }
      end

      def new
        message = System::Message.new
        authorize message
        render_new(message)
      end

      def create
        message = System::Message.new(message_params)
        authorize message
        if message.save
          redirect_to system_messages_path
        else
          render_new(message)
        end
      end

      def edit
        render_edit(find_and_authorise_message)
      end

      def update
        message = find_and_authorise_message
        if message.update(message_params)
          redirect_to system_messages_path
        else
          render_edit(message)
        end
      end

      def destroy
        find_and_authorise_message.destroy!
        redirect_to system_messages_path
      end

      private

      def render_new(message)
        render :new, locals: { message: message }
      end

      def render_edit(message)
        render :edit, locals: { message: message }
      end

      def message_params
        params
          .require(:message)
          .permit(:title, :body, :severity, :message_type, :display_from, :display_until)
      end

      def find_and_authorise_message
        message = Message.find(params[:id])
        authorize message
        message
      end
    end
  end
end

Version data entries

134 entries across 134 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.1.0 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.167 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.166 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.165 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.164 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.163 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.162 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.161 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.160 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.159 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.158 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.157 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.156 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.155 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.153 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.152 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.151 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.149 app/controllers/renalware/system/messages_controller.rb
renalware-core-2.0.148 app/controllers/renalware/system/messages_controller.rb