<commit_before>class CategoriesController < ApplicationController
  before_filter :require_admin
  skip_before_filter :require_admin, :only => [:index, :show]

  include ActivationHelper

  def index
    if (params[:show_deleted])
      @categories = Category.all
    else
      @categories = Category.active
    end
  end

  def show
    @category = Category.find(params[:id])
  end

  def new
    @category = Category.new
  end

  def create
    @category = Category.new(params[:category])
    @category.sort_order = params[:category][:sort_order].to_i
    if @category.save
      flash[:notice] = "Successfully created category."
      redirect_to @category
    else
      flash[:error] = "Oops! Something went wrong with creating the category."
      render :action => 'new'
    end
  end

  def edit
    @category = Category.find(params[:id])
  end

  def update
    @category = Category.find(params[:id])
    @category.sort_order = params[:category][:sort_order].to_i
    if @category.update_attributes(params[:category])
      flash[:notice] = "Successfully updated category."
      redirect_to @category
    else
      render :action => 'edit'
    end
  end

  def destroy
    @category = Category.find(params[:id])
    @category.destroy(:force)
    flash[:notice] = "Successfully destroyed category."
    redirect_to categories_url
  end
end<commit_msg>Small refactor of categories controller<commit_after>class CategoriesController < ApplicationController

  before_filter :require_admin
  before_filter :set_current_category, :only => [:show, :edit, :update, :destroy]
  skip_before_filter :require_admin, :only => [:index, :show]

  include ActivationHelper

  # --------- before filter methods -------- #
  def set_current_category
    @category = Category.find(params[:id])
  end
  # --------- end before filter methods -------- #

  def index
    if (params[:show_deleted])
      @categories = Category.all
    else
      @categories = Category.active
    end
  end

  def show
  end

  def new
    @category = Category.new
  end

  def create
    @category = Category.new(params[:category])
    @category.sort_order = params[:category][:sort_order].to_i
    if @category.save
      flash[:notice] = "Successfully created category."
      redirect_to @category
    else
      flash[:error] = "Oops! Something went wrong with creating the category."
      render :action => 'new'
    end
  end

  def edit
  end

  def update
    @category.sort_order = params[:category][:sort_order].to_i
    if @category.update_attributes(params[:category])
      flash[:notice] = "Successfully updated category."
      redirect_to @category
    else
      render :action => 'edit'
    end
  end

  def destroy
    @category.destroy(:force)
    flash[:notice] = "Successfully destroyed category."
    redirect_to categories_url
  end
end
{'fraction_non_alphanumeric': 0.11142454160789844, 'fraction_numerical': 0.0, 'mean_word_length': 3.190546528803545, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5701274', 'n_tokens_mistral': 827, 'n_tokens_neox': 804, 'n_words': 214}