<commit_before>include OwnershipAuthentication

class ReadingsController < ApplicationController
  before_action :authenticate_user!, except: [:show, :index]
  before_action :set_reading, only: [:show, :edit, :update, :destroy]
  before_action :reading_owner?, except: [:show]

  def new
    @reading_group_id = params[:reading_group_id]
    @reading = Reading.new
  end

  def create
    @reading = Reading.new(reading_params)
    @reading.group_id = params[:reading_group_id].to_i
    respond_to do |format|
      create_and_redir(format)
    end
  end

  # GET /readings/1/edit
  def edit
    @reading_group_id = params[:reading_group_id]
  end

  # PUT /reading_groups/1/readings/1
  # PUT /reading_groups/1/readings/1.json
  def update
    @reading.group_id = params[:reading_group_id].to_i
    respond_to do |format|
      if @reading.update(reading_params)
        format.html { redirect_to(reading_group_path(params[:reading_group_id].to_i), notice: 'Reading was successfully updated.') }
        format.json { head :no_content }
      else
        failed_action(format, 'edit')
      end
    end
  end

  # DELETE /reading_groups/1/readings/1
  # DELETE /reading_groups/1/readings/1
  def destroy
    @reading.destroy
    respond_to do |format|
      format.html { redirect_to reading_group_path(params[:reading_group_id].to_i) }
      format.json { head :no_content }
    end
  end

  private

  # Never trust parameters from the scary internet, only allow the white list through.
  def reading_params
    params[:reading]
  end

  # Duplicated code on create and update actions extracted here
  def failed_action(format, destiny_action)
    @reading_group_id = params[:reading_group_id]

    format.html { render action: destiny_action }
    format.json { render json: @reading.errors, status: :unprocessable_entity }
  end

  # Code extracted from create action
  def create_and_redir(format)
    if @reading.save
      format.html { redirect_to reading_group_path(@reading.group_id), notice: 'Reading was successfully created.' }
    else
      failed_action(format, 'new')
    end
  end

  def set_reading
    @reading = Reading.find(params[:id].to_i)
  end
end
<commit_msg>There's no show action for ReadingsController<commit_after>include OwnershipAuthentication

class ReadingsController < ApplicationController
  before_action :authenticate_user!, except: [:index]
  before_action :set_reading, only: [:edit, :update, :destroy]
  before_action :reading_owner?, except: [:new]

  def new
    @reading_group_id = params[:reading_group_id]
    @reading = Reading.new
  end

  def create
    @reading = Reading.new(reading_params)
    @reading.group_id = params[:reading_group_id].to_i
    respond_to do |format|
      create_and_redir(format)
    end
  end

  # GET /readings/1/edit
  def edit
    @reading_group_id = params[:reading_group_id]
  end

  # PUT /reading_groups/1/readings/1
  # PUT /reading_groups/1/readings/1.json
  def update
    @reading.group_id = params[:reading_group_id].to_i
    respond_to do |format|
      if @reading.update(reading_params)
        format.html { redirect_to(reading_group_path(params[:reading_group_id].to_i), notice: 'Reading was successfully updated.') }
        format.json { head :no_content }
      else
        failed_action(format, 'edit')
      end
    end
  end

  # DELETE /reading_groups/1/readings/1
  # DELETE /reading_groups/1/readings/1
  def destroy
    @reading.destroy
    respond_to do |format|
      format.html { redirect_to reading_group_path(params[:reading_group_id].to_i) }
      format.json { head :no_content }
    end
  end

  private

  # Never trust parameters from the scary internet, only allow the white list through.
  def reading_params
    params[:reading]
  end

  # Duplicated code on create and update actions extracted here
  def failed_action(format, destiny_action)
    @reading_group_id = params[:reading_group_id]

    format.html { render action: destiny_action }
    format.json { render json: @reading.errors, status: :unprocessable_entity }
  end

  # Code extracted from create action
  def create_and_redir(format)
    if @reading.save
      format.html { redirect_to reading_group_path(@reading.group_id), notice: 'Reading was successfully created.' }
    else
      failed_action(format, 'new')
    end
  end

  def set_reading
    @reading = Reading.find(params[:id].to_i)
  end
end

{'fraction_non_alphanumeric': 0.09037104484407012, 'fraction_numerical': 0.004097427725927612, 'mean_word_length': 3.664543524416136, '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': '3296786', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1372, 'n_words': 333}