<commit_before>require_dependency "datatable_state/application_controller"

module DatatableState
  class StoreController < ApplicationController
    respond_to :json
    before_filter :get_state

    def save
      if @store
        @store.update_attributes(params[:datatable_state])
      else
        @store = Store.new(params[:datatable_state])
        @store.user = current_user
      end

      respond_to do |format|
        if @store.save
          format.json { render json: @store, status: :created }
        else
          format.json { render json: @store.errors, status: :unprocessable_entity }
        end
      end
    end

    def load
      result = if @store
        @store.state
      else
        {}.as_json
      end
      respond_with result
    end

    private

    def get_state
      @store = Store.find_by_user_id_and_path(current_user.id,
        params[:datatable_state][:path])
    end
  end
end<commit_msg>Implement save with strong_parameters with fallback when unavailable.<commit_after>require_dependency "datatable_state/application_controller"

module DatatableState
  class StoreController < ApplicationController
    respond_to :json
    before_filter :get_state

    def save
      if @store
        @store.update_attributes(store_params)
      else
        @store = Store.new(store_params)
        @store.user = current_user
      end

      respond_to do |format|
        if @store.save
          format.json { render json: @store, status: :created }
        else
          format.json { render json: @store.errors, status: :unprocessable_entity }
        end
      end
    end

    def load
      result = if @store
        @store.state
      else
        {}.as_json
      end
      respond_with result
    end

    private

    def get_state
      @store = Store.find_by_user_id_and_path(current_user.id,
        params[:datatable_state][:path])
    end

    def store_params
      begin
        params.require(:datatable_state).permit(:path, :state)
      rescue
        params[:datatable_state]
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0706337687469763, 'fraction_numerical': 0.0, 'mean_word_length': 2.2982456140350878, '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': '929723', 'n_tokens_mistral': 603, 'n_tokens_neox': 590, 'n_words': 143}