<commit_before>module Fae
  class BaseController < ApplicationController

    before_action :set_class_variables
    before_action :set_item, only: [:edit, :update, :destroy]

    helper FormHelper

    def index
      @items = @klass.for_fae_index
    end

    def new
      @item = @klass.new
      build_assets
    end

    def edit
      build_assets
    end

    def create
      @item = @klass.new(item_params)

      if @item.save
        redirect_to @index_path, notice: "Success. You’ve done good."
      else
        build_assets
        render action: 'new', error: "Let’s slow down a bit. Check your form for errors."
      end
    end

    def update
      if @item.update(item_params)
        redirect_to @index_path, notice: "Success. You’ve done good."
      else
        build_assets
        render action: 'edit', error: "Let’s slow down a bit. Check your form for errors."
      end
    end

    def destroy
      if @item.destroy
        redirect_to @index_path, notice: 'Item was successfully removed'
      else
        redirect_to @index_path, flash: { error: 'This item has associated objects that prevent it from being removed.' }
      end
    end

  private

    def set_class_variables(class_name=nil)
      @klass_base = params[:controller].split('/').last
      @klass_name = class_name || @klass_base
      @klass = @klass_base.classify.constantize
      @klass_singular = @klass_name.singularize
      @klass_humanized = @klass_singular.humanize
      @index_path = '/'+params[:controller]
      @cancelled_path = @index_path+'?cancelled=true'
      @new_path = @index_path+'/new'
    end

    # Use callbacks to share common setup or constraints between actions.
    def set_item
      @item = @klass.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def item_params
      params.require(@klass_base.singularize).permit!
    end

    # if model has images or files, build them here for nesting
    def build_assets
    end

  end
end
<commit_msg>fixes sortable tables breaking when you define a custom class_variable<commit_after>module Fae
  class BaseController < ApplicationController

    before_action :set_class_variables
    before_action :set_item, only: [:edit, :update, :destroy]

    helper FormHelper

    def index
      @items = @klass.for_fae_index
    end

    def new
      @item = @klass.new
      build_assets
    end

    def edit
      build_assets
    end

    def create
      @item = @klass.new(item_params)

      if @item.save
        redirect_to @index_path, notice: "Success. You’ve done good."
      else
        build_assets
        render action: 'new', error: "Let’s slow down a bit. Check your form for errors."
      end
    end

    def update
      if @item.update(item_params)
        redirect_to @index_path, notice: "Success. You’ve done good."
      else
        build_assets
        render action: 'edit', error: "Let’s slow down a bit. Check your form for errors."
      end
    end

    def destroy
      if @item.destroy
        redirect_to @index_path, notice: 'Item was successfully removed'
      else
        redirect_to @index_path, flash: { error: 'This item has associated objects that prevent it from being removed.' }
      end
    end

  private

    def set_class_variables(class_name=nil)
      @klass_base = params[:controller].split('/').last
      @klass_name = class_name || @klass_base
      @klass = @klass_base.classify.constantize
      @klass_singular = @klass_base.singularize
      @klass_humanized = @klass_name.singularize.humanize
      @index_path = '/'+params[:controller]
      @cancelled_path = @index_path+'?cancelled=true'
      @new_path = @index_path+'/new'
    end

    # Use callbacks to share common setup or constraints between actions.
    def set_item
      @item = @klass.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def item_params
      params.require(@klass_base.singularize).permit!
    end

    # if model has images or files, build them here for nesting
    def build_assets
    end

  end
end

{'fraction_non_alphanumeric': 0.08213502315378991, 'fraction_numerical': 0.0, 'mean_word_length': 2.5968448729184925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1543858', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1224, 'n_words': 375}