Sha256: 5f56795383e2377ca0785ca9364b25f38b8852aa59cf636ef20c04c1561ad3b8

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

class HelpCenter::SupportCategoriesController < HelpCenter::ApplicationController
  before_action :authenticate_user!, only: [:edit, :update, :destroy]
  before_action :set_category, only: [:index, :show, :edit, :update, :destroy]
  before_action :require_mod_or_author_for_thread!, only: [:edit, :update, :destroy]


  def index
    @support_threads = SupportThread.where(support_category: @category) if @category.present?
    @support_threads = @support_threads.pinned_first.sorted.includes(:user, :support_category)
    @pagy, @records = pagy(@support_threads)
    render "help_center/support_threads/index"
  end

  def new
    @category = SupportCategory.new
  end

  def show
  end

  def create
    @category = SupportCategory.new(support_category_params)

    if @category.save
      redirect_to help_center.support_threads_path
    else
      render action: :new
    end
  end

  def edit
  end

  def update
    if @category.update(support_category_params)
      redirect_to help_center.support_category_path(@category), notice: I18n.t('your_changes_were_saved')
    else
      render action: :edit
    end
  end

  def destroy
    @category.destroy
    redirect_to help_center.support_threads_path, notice: I18n.t('successfully_deleted')
  end

  private

    def set_category
      @category = SupportCategory.friendly.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      redirect_to help_center.support_threads_path
    end

    def support_category_params
      params.require(:support_category).permit(:name, :color, :position)
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
help_center-0.0.7 app/controllers/help_center/support_categories_controller.rb
help_center-0.0.6 app/controllers/help_center/support_categories_controller.rb