<commit_before>class ResponseSetsController < ApplicationController
  before_action :set_response_set, only: [:show, :edit, :update, :destroy]
  load_and_authorize_resource

  # GET /response_sets
  # GET /response_sets.json
  def index
    @response_sets = ResponseSet.all
  end

  # GET /response_sets/1
  # GET /response_sets/1.json
  def show
  end

  # GET /response_sets/new
  def new
    @response_set = ResponseSet.new
    @response_set.responses.build
  end

  # GET /response_sets/1/edit
  def edit
  end

  def assign_author
    # Populating author field
    @response_set.created_by = current_user
    @response_set.updated_by = current_user
  end

  # POST /response_sets
  # POST /response_sets.json
  def create
    @response_set = ResponseSet.new(response_set_params)
    assign_author

    respond_to do |format|
      if @response_set.save
        format.html { redirect_to @response_set, notice: 'Response set was successfully created.' }
        format.json { render :show, status: :created, location: @response_set }
      else
        format.html { render :new }
        format.json { render json: @response_set.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /response_sets/1
  # PATCH/PUT /response_sets/1.json
  def update
    @response_set.updated_by = current_user

    respond_to do |format|
      if @response_set.update(response_set_params)
        format.html { redirect_to @response_set, notice: 'Response set was successfully updated.' }
        format.json { render :show, status: :ok, location: @response_set }
      else
        format.html { render :edit }
        format.json { render json: @response_set.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /response_sets/1
  # DELETE /response_sets/1.json
  def destroy
    @response_set.destroy
    respond_to do |format|
      format.html { redirect_to response_sets_url, notice: 'Response set was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private

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

  # Never trust parameters from the scary internet, only allow the white list through.
  def response_set_params
    params.require(:response_set).permit(:name, :description, :oid, :author, :coded,
                                         responses_attributes: [:value, :display_name, :code_system])
  end
end<commit_msg>Fixed issue where responses were being duplicated<commit_after>class ResponseSetsController < ApplicationController
  before_action :set_response_set, only: [:show, :edit, :update, :destroy]
  load_and_authorize_resource

  # GET /response_sets
  # GET /response_sets.json
  def index
    @response_sets = ResponseSet.all
  end

  # GET /response_sets/1
  # GET /response_sets/1.json
  def show
  end

  # GET /response_sets/new
  def new
    @response_set = ResponseSet.new
    @response_set.responses.build
  end

  # GET /response_sets/1/edit
  def edit
  end

  def assign_author
    # Populating author field
    @response_set.created_by = current_user
    @response_set.updated_by = current_user
  end

  # POST /response_sets
  # POST /response_sets.json
  def create
    @response_set = ResponseSet.new(response_set_params)
    assign_author

    respond_to do |format|
      if @response_set.save
        format.html { redirect_to @response_set, notice: 'Response set was successfully created.' }
        format.json { render :show, status: :created, location: @response_set }
      else
        format.html { render :new }
        format.json { render json: @response_set.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /response_sets/1
  # PATCH/PUT /response_sets/1.json
  def update
    @response_set.updated_by = current_user

    respond_to do |format|
      if @response_set.update(response_set_params)
        format.html { redirect_to @response_set, notice: 'Response set was successfully updated.' }
        format.json { render :show, status: :ok, location: @response_set }
      else
        format.html { render :edit }
        format.json { render json: @response_set.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /response_sets/1
  # DELETE /response_sets/1.json
  def destroy
    @response_set.destroy
    respond_to do |format|
      format.html { redirect_to response_sets_url, notice: 'Response set was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private

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

  # Never trust parameters from the scary internet, only allow the white list through.
  def response_set_params
    params.require(:response_set).permit(:name, :description, :oid, :author, :coded,
                                         responses_attributes: [:id, :value, :display_name, :code_system])
  end
end
{'fraction_non_alphanumeric': 0.08262502470844041, 'fraction_numerical': 0.0027673453251630758, 'mean_word_length': 3.0938511326860842, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4321864', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1507, 'n_words': 408}