Sha256: cc8de37fde433a4bb5292a970c27ea3b5447ef390ed689ed9ac02a2f0b1f476b

Contents?: true

Size: 1.61 KB

Versions: 14

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true
require_dependency "decidim/system/application_controller"

module Decidim
  module System
    # Controller that allows managing all the Admins.
    #
    class AdminsController < ApplicationController
      def index
        @admins = Admin.all
      end

      def new
        @form = AdminForm.new
      end

      def create
        @form = AdminForm.from_params(params)

        CreateAdmin.call(@form) do
          on(:ok) do
            flash[:notice] = I18n.t("admins.create.success", scope: "decidim.system")
            redirect_to admins_path
          end

          on(:invalid) do
            flash.now[:alert] = I18n.t("admins.create.error", scope: "decidim.system")
            render :new
          end
        end
      end

      def edit
        @admin = Admin.find(params[:id])
        @form = AdminForm.from_model(@admin)
      end

      def update
        @admin = Admin.find(params[:id])
        @form = AdminForm.from_params(params)

        UpdateAdmin.call(@admin, @form) do
          on(:ok) do
            flash[:notice] = I18n.t("admins.update.success", scope: "decidim.system")
            redirect_to admins_path
          end

          on(:invalid) do
            flash.now[:alert] = I18n.t("admins.update.error", scope: "decidim.system")
            render :edit
          end
        end
      end

      def show
        @admin = Admin.find(params[:id])
      end

      def destroy
        @admin = Admin.find(params[:id]).destroy!
        flash[:notice] = I18n.t("admins.destroy.success", scope: "decidim.system")

        redirect_to admins_path
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
decidim-system-0.0.1.alpha9 app/controllers/decidim/system/admins_controller.rb
decidim-0.0.1.alpha9 decidim-system/app/controllers/decidim/system/admins_controller.rb
decidim-system-0.0.1.alpha8 app/controllers/decidim/system/admins_controller.rb
decidim-0.0.1.alpha8 decidim-system/app/controllers/decidim/system/admins_controller.rb
decidim-system-0.0.1.alpha7 app/controllers/decidim/system/admins_controller.rb
decidim-0.0.1.alpha7 decidim-system/app/controllers/decidim/system/admins_controller.rb
decidim-system-0.0.1.alpha6 app/controllers/decidim/system/admins_controller.rb
decidim-0.0.1.alpha6 decidim-system/app/controllers/decidim/system/admins_controller.rb
decidim-system-0.0.1.alpha5 app/controllers/decidim/system/admins_controller.rb
decidim-0.0.1.alpha5 decidim-system/app/controllers/decidim/system/admins_controller.rb
decidim-system-0.0.1.alpha4 app/controllers/decidim/system/admins_controller.rb
decidim-0.0.1.alpha4 decidim-system/app/controllers/decidim/system/admins_controller.rb
decidim-system-0.0.1.alpha3 app/controllers/decidim/system/admins_controller.rb
decidim-0.0.1.alpha3 decidim-system/app/controllers/decidim/system/admins_controller.rb