BigW Consortium Gitlab

labels_controller.rb 1 KB
Newer Older
Valery Sizov committed
1 2 3 4
class Admin::LabelsController < Admin::ApplicationController
  before_action :set_label, only: [:show, :edit, :update, :destroy]

  def index
5
    @labels = Label.templates.page(params[:page])
Valery Sizov committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  end

  def show
  end

  def new
    @label = Label.new
  end

  def edit
  end

  def create
    @label = Label.new(label_params)
    @label.template = true

    if @label.save
      redirect_to admin_labels_url, notice: "Label was created"
    else
      render :new
    end
  end

  def update
    if @label.update(label_params)
      redirect_to admin_labels_path, notice: 'label was successfully updated.'
    else
      render :edit
    end
  end

  def destroy
    @label.destroy
    @labels = Label.templates

    respond_to do |format|
      format.html do
        redirect_to(admin_labels_path, notice: 'Label was removed')
      end
      format.js
    end
  end

  private

  def set_label
    @label = Label.find(params[:id])
  end

  def label_params
Tap committed
56
    params[:label].permit(:title, :description, :color)
Valery Sizov committed
57 58
  end
end