<commit_before>class AdminController < ActionController::Base

  include AdminHelper

  before_filter :authenticate_admin
  before_action :set_defaults, :except => [:dashboard]
  before_action :set_routes, :except => [:dashboard]
  protect_from_forgery :with => :exception

  def dashboard
    redirect_to admin_users_path
  end

  def index
    @items = @model.all
  end

  def new
    @item = @model.new
    @url = @routes[:index]
  end

  def edit
    @url = @routes[:show]
  end

  def create
    @item = @model.new(create_params)
    convert_dates if @item.attributes.has_key?('active_at')
    @item = @model.new(create_params)
    if @item.attributes.has_key? 'slug' && !create_params[:slug].blank?
      @item.slug = @item.make_slug_unique(create_params[:slug])
    end
    if @item.save
      @routes[:edit] = send("edit_admin_#{model_table_singular}_path", @item)
      redirect_to @routes[:edit], :notice => "#{@model.to_s} was successfully created."
    else
      render :action => "new"
    end
  end

  def update
    convert_dates if @item.attributes.has_key?('active_at')
    update_params ||= create_params
    if @item.attributes.has_key? 'slug' && !update_params[:slug].blank?
      update_params[:slug] = @item.make_slug_unique(update_params[:slug])
    end
    if @item.update(update_params)
      @routes[:edit] = send("edit_admin_#{model_table_singular}_path", @item)
      redirect_to @routes[:edit], :notice => "#{@model.to_s} was updated successfully."
    else
      render :action => "edit"
    end
  end

  def destroy
    @item.destroy
    redirect_to @routes[:index], :notice => "#{@model.to_s} was deleted successfully."
  end

  private

    def authenticate_admin
      authenticate_user!
      redirect_to root_path unless current_user.is_admin?
    end

    def set_defaults
      @columns = ['title']
      @actions = [:edit, :delete]
    end<commit_msg>add routes to rendering form errors in post methods in admin controller<commit_after>class AdminController < ActionController::Base

  include AdminHelper

  before_filter :authenticate_admin
  before_action :set_defaults, :except => [:dashboard]
  before_action :set_routes, :except => [:dashboard]
  protect_from_forgery :with => :exception

  def dashboard
    redirect_to admin_users_path
  end

  def index
    @items = @model.all
  end

  def new
    @item = @model.new
    @url = @routes[:index]
  end

  def edit
    @url = @routes[:show]
  end

  def create
    @item = @model.new(create_params)
    convert_dates if @item.attributes.has_key?('active_at')
    @item = @model.new(create_params)
    if @item.attributes.has_key? 'slug' && !create_params[:slug].blank?
      @item.slug = @item.make_slug_unique(create_params[:slug])
    end
    if @item.save
      @routes[:edit] = send("edit_admin_#{model_table_singular}_path", @item)
      redirect_to @routes[:edit], :notice => "#{@model.to_s} was successfully created."
    else
      @url = @routes[:index]
      render :action => "new"
    end
  end

  def update
    convert_dates if @item.attributes.has_key?('active_at')
    update_params ||= create_params
    if @item.attributes.has_key? 'slug' && !update_params[:slug].blank?
      update_params[:slug] = @item.make_slug_unique(update_params[:slug])
    end
    if @item.update(update_params)
      @routes[:edit] = send("edit_admin_#{model_table_singular}_path", @item)
      redirect_to @routes[:edit], :notice => "#{@model.to_s} was updated successfully."
    else
      @url = @routes[:show]
      render :action => "edit"
    end
  end

  def destroy
    @item.destroy
    redirect_to @routes[:index], :notice => "#{@model.to_s} was deleted successfully."
  end

  private

    def authenticate_admin
      authenticate_user!
      redirect_to root_path unless current_user.is_admin?
    end

    def set_defaults
      @columns = ['title']
      @actions = [:edit, :delete]
    end
{'fraction_non_alphanumeric': 0.12471131639722864, 'fraction_numerical': 0.0, 'mean_word_length': 3.5644028103044496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '533596', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1289, 'n_words': 282}