<commit_before>module Pbw
	class BaseModelsController < BaseController
		attr_accessor :model_class

		before_filter :authenticate_user!
		before_filter :set_model_class
		before_filter :model_for_read, :only => [:show]
		before_filter :model_for_update, :only => [:edit, :update, :destroy]
		before_filter :index_models, :only => [:index]
		before_filter :model_for_create, :only => [:new, :create]

		def set_model_class
			# stub method
		end

		def update_model_before_create(model)
			# stub method
		end

		def update_model_before_update(model)
			# stub method
		end

		def index
	  		session[:referrer] = request.url
	  		if @models && !@models.empty?
				render json: @models.to_json
			else
				render json: '', status: :unprocessable_entity
			end
		end

		def show
			render json: @model.to_json
		end

		def create
			if @model.save
				render json: @model.to_json
			else
				render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
			end
		end

		def update
			if @model.update_attributes(params)
				render json: @model.to_json
			else
				render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
			end
		end

		def destroy
			if @model.destroy
				head :no_content
			else
				render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
			end
		end

		def real_model_class
			begin
				unless params[:_type].blank?
					klass = Kernel.get_const(params[:_type])
					return klass if klass.ancestors.include?(self.model_class)
				end
			rescue
			end
			self.model_class
		end

		def model_id
			params[:id]
		end

		def index_models
			authorize! :manage, real_model_class
			@models = model_class.desc(:created_at)
		end

		def model_for_create
			authorize! :create, real_model_class
			@model = real_model_class.new(params)
			@model.accessible = :all
			update_model_before_create(@model)
		end

	  	def model_for_read
			@model = real_model_class.find(model_id)<commit_msg>Fix index to return only derived class<commit_after>module Pbw
	class BaseModelsController < BaseController
		attr_accessor :model_class

		before_filter :authenticate_user!
		before_filter :set_model_class
		before_filter :model_for_read, :only => [:show]
		before_filter :model_for_update, :only => [:edit, :update, :destroy]
		before_filter :index_models, :only => [:index]
		before_filter :model_for_create, :only => [:new, :create]

		def set_model_class
			# stub method
		end

		def update_model_before_create(model)
			# stub method
		end

		def update_model_before_update(model)
			# stub method
		end

		def index
	  		session[:referrer] = request.url
	  		if @models && !@models.empty?
				render json: @models.to_json
			else
				render json: '', status: :unprocessable_entity
			end
		end

		def show
			render json: @model.to_json
		end

		def create
			if @model.save
				render json: @model.to_json
			else
				render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
			end
		end

		def update
			if @model.update_attributes(params)
				render json: @model.to_json
			else
				render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
			end
		end

		def destroy
			if @model.destroy
				head :no_content
			else
				render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
			end
		end

		def real_model_class
			begin
				unless params[:_type].blank?
					klass = Kernel.get_const(params[:_type])
					return klass if klass.ancestors.include?(self.model_class)
				end
			rescue
			end
			self.model_class
		end

		def model_id
			params[:id]
		end

		def index_models
			authorize! :manage, real_model_class
			@models = real_model_class.desc(:created_at)
		end

		def model_for_create
			authorize! :create, real_model_class
			@model = real_model_class.new(params)
			@model.accessible = :all
			update_model_before_create(@model)
		end

	  	def model_for_read
			@model = real_model_class.find(model_id)
{'fraction_non_alphanumeric': 0.08438605356240525, 'fraction_numerical': 0.0, 'mean_word_length': 3.6741440377804016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4254667', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1341, 'n_words': 315}