<commit_before>module Api
  class RecordsController < ApplicationController
    before_action :ensure_signed_in, except: [:index, :show]

    def create
      @record = Record.new(record_params)

      if @record.save
        UserContribution.create(
          user_id: current_user.id,
          record_id: @record.id
        )

        render json: @record
      else
        render json: @record.errors.full_messages, status: 422
      end
    end

    def update
      @record = Record.find(params[:id])

      if @record.update(record_update_params)
        unless current_user.contributions.include?(@record)
          UserContribution.create(
            user_id: current_user.id,
            record_id: @record.id
          )
        end

        render json: @record
      else
        render json @record.errors.full_messages, status: 422
      end
    end

    def destroy
      @record = Record.find(params[:id])
      @record.destroy!

      render json: @record
    end

    def show
      @record = Record
                  .includes(:comments)
                  .includes(:contributors)
                  .includes(:collected)
                  .includes(:wanted)
                  .find(params[:id])

      render :show
    end

    def index
      @records = Record.all

      render :index
    end

    private

    def record_params
      params
        .require(:record)
        .permit(
          :title,
          :image,
          :artist_name,
          :artist_id,
          :label_name,
          :label_id,
          :cat_no,
          :genre_ids,
          :country_id,
          :year,
          :notes,
          tracks_attributes: [
            :id,
            :ord,
            :position,
            :title,
            :duration
          ]
        )
    end

    def record_update_params
      params
        .require(:record)
        .permit(
          :image,
          :label_name,
          :label_id,
          :cat_no,
          :genre_ids,
          :country_id,
          :year,
          :notes,
          tracks_attributes: [
            :id,
            :ord,
            :position,
            :title,
            :duration,
            :_destroy
          ]
        )
    end
  end
end
<commit_msg>Update RecordsController params for AJAX checkboxes<commit_after>module Api
  class RecordsController < ApplicationController
    before_action :ensure_signed_in, except: [:index, :show]

    def create
      @record = Record.new(record_params)

      if @record.save
        UserContribution.create(
          user_id: current_user.id,
          record_id: @record.id
        )

        render json: @record
      else
        render json: @record.errors.full_messages, status: 422
      end
    end

    def update
      @record = Record.find(params[:id])

      if @record.update(record_update_params)
        unless current_user.contributions.include?(@record)
          UserContribution.create(
            user_id: current_user.id,
            record_id: @record.id
          )
        end

        render json: @record
      else
        render json @record.errors.full_messages, status: 422
      end
    end

    def destroy
      @record = Record.find(params[:id])
      @record.destroy!

      render json: @record
    end

    def show
      @record = Record
                  .includes(:comments)
                  .includes(:contributors)
                  .includes(:collected)
                  .includes(:wanted)
                  .find(params[:id])

      render :show
    end

    def index
      @records = Record.all

      render :index
    end

    private

    def record_params
      params
        .require(:record)
        .permit(
          :title,
          :image,
          :artist_name,
          :artist_id,
          :label_name,
          :label_id,
          :cat_no,
          :country_id,
          :year,
          :notes,
          genre_ids: [],
          tracks_attributes: [
            :id,
            :ord,
            :position,
            :title,
            :duration
          ]
        )
    end

    def record_update_params
      params
        .require(:record)
        .permit(
          :image,
          :label_name,
          :label_id,
          :cat_no,
          :country_id,
          :year,
          :notes,
          genre_ids: [],
          tracks_attributes: [
            :id,
            :ord,
            :position,
            :title,
            :duration,
            :_destroy
          ]
        )
    end
  end
end

{'fraction_non_alphanumeric': 0.08458149779735682, 'fraction_numerical': 0.0026431718061674008, 'mean_word_length': 1.2911200807265388, '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': '1355995', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1244, 'n_words': 269}