<commit_before>module Glass
  class ApiController < Glass::ApplicationController
    before_filter :sanitize_model
    before_filter :sanitize_params, only: [:create, :update]

    respond_to :json

    def index
      render json: @model.all.to_json
    end

    def show
      render json: @model.find(params[:id]).to_json
    end

    def create
      object = @model.new(params[@params])

      if object.save
        render json: object.to_json
      else
        render json: object.errors, status: :unprocessable_entity
      end
    end

    def update
      object = @model.find(params[:id])

      if object.update_attributes(params[@params])
        render json: object.to_json
      else
        render json: object.errors, status: :unprocessable_entity
      end
    end

    def destroy
      object = @model.find(params[:id])

      if object.delete
        render json: 'Successfully deleted'
      else
        render json: 'Unable to delete entity', status: :unprocessable_entity
      end
    end

  private
    def sanitize_model
      @model = params[:model_scope].capitalize.singularize.constantize
    end

    def sanitize_params
      @params = params[:object].downcase.to_sym
    end
  end
end<commit_msg>Fixes create and update in Api Controller<commit_after>module Glass
  class ApiController < Glass::ApplicationController
    before_filter :sanitize_model
    before_filter :sanitize_params, only: [:create, :update]

    respond_to :json

    def index
      render json: @model.all.to_json
    end

    def show
      render json: @model.find(params[:id]).to_json
    end

    def create
      object = @model.new(params[@key])

      if object.save
        render json: object.to_json
      else
        render json: object.errors, status: :unprocessable_entity
      end
    end

    def update
      object = @model.find(params[:id])

      if object.update_attributes(params[@key])
        render json: object.to_json
      else
        render json: object.errors, status: :unprocessable_entity
      end
    end

    def destroy
      object = @model.find(params[:id])

      if object.delete
        render json: 'Successfully deleted'
      else
        render json: 'Unable to delete entity', status: :unprocessable_entity
      end
    end

  private
    def sanitize_model
      @model = params[:model_scope].capitalize.singularize.constantize
    end

    def sanitize_params
      @key = params[:model_scope].to_sym
    end
  end
end
{'fraction_non_alphanumeric': 0.07953169156237384, 'fraction_numerical': 0.0, 'mean_word_length': 2.54, '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': '2635012', 'n_tokens_mistral': 731, 'n_tokens_neox': 711, 'n_words': 193}