<commit_before>class TopicsController < ApplicationController
  before_action :authenticate_participant!, except: [:index, :show]
  before_action :set_topic, only: [:edit, :update, :destroy]
  before_action :set_challenge
  after_action :verify_authorized, except: [:index]

  def index
    @topics = @challenge.topics.page(params[:page]).per(20)
  end

  def new
    @topic = @challenge.topics.new
    @comment = @topic.comments.new
    authorize @topic
  end

  def edit
  end

  def create
    @topic = @challenge.topics.new(topic_params)
    authorize @topic
    if @topic.save
      EveryTopicNotificationJob
        .set(wait: 5.minutes)
        .perform_later(@topic.id)
      end
      redirect_to challenge_topics_path(@challenge), notice: 'Topic was successfully created.'
    else
      render :new
    end
  end

  def update
    # https://github.com/norman/friendly_id/issues/185
    if @topic.update(topic_params)
      nested = params['topic']['comment']
      if nested.present?
        comment = Comment.find(nested['id'])
        comment.update(comment_markdown: nested['comment_markdown'])
      end
      redirect_to challenge_topics_path(@challenge), notice: 'Topic was successfully updated.'
    else
      render :edit
    end
  end

  def destroy
    @topic.destroy<commit_msg>fix  warning: else without rescue is useless<commit_after>class TopicsController < ApplicationController
  before_action :authenticate_participant!, except: [:index, :show]
  before_action :set_topic, only: [:edit, :update, :destroy]
  before_action :set_challenge
  after_action :verify_authorized, except: [:index]

  def index
    @topics = @challenge.topics.page(params[:page]).per(20)
  end

  def new
    @topic = @challenge.topics.new
    @comment = @topic.comments.new
    authorize @topic
  end

  def edit
  end

  def create
    @topic = @challenge.topics.new(topic_params)
    authorize @topic
    if @topic.save
      EveryTopicNotificationJob
        .set(wait: 5.minutes)
        .perform_later(@topic.id)
      redirect_to challenge_topics_path(@challenge), notice: 'Topic was successfully created.'
    else
      render :new
    end
  end

  def update
    # https://github.com/norman/friendly_id/issues/185
    if @topic.update(topic_params)
      nested = params['topic']['comment']
      if nested.present?
        comment = Comment.find(nested['id'])
        comment.update(comment_markdown: nested['comment_markdown'])
      end
      redirect_to challenge_topics_path(@challenge), notice: 'Topic was successfully updated.'
    else
      render :edit
    end
  end

  def destroy
    @topic.destroy
{'fraction_non_alphanumeric': 0.10255432710636675, 'fraction_numerical': 0.004574914220358368, 'mean_word_length': 3.308702791461412, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3813944', 'n_tokens_mistral': 834, 'n_tokens_neox': 775, 'n_words': 186}