<commit_before>class ContentsController < ApplicationController
  def index
    @contents = Form.find(params[:form_id]).contents.includes(:submissions)
  end

  def create
    @content = Form.find(params[:form_id]).contents.create(content_params)
  end

  def update
    @content = Content.find(params[:id])
    if @content.nil?
      render json: {message: 'Cannot find content'}, status: :not_found
    elsif @content.update(content_params)
      render json: {updated: true}, status: :success
    end
  end

  def delete
    @content = Content.find(params[:id])
    if @content.nil?
      render json: {message: 'Cannot find content'}, status: :not_found
    elsif @content.destroy
      render json: {deleted: true}, status: :success
    end
  end

  private

  def content_params
    params.require(:content).permit(:type,:index,:label,:options)<commit_msg>ft(content_controller): updated delete and update methods<commit_after>class ContentsController < ApplicationController
  def index
    @contents = Form.find(params[:form_id]).contents.includes(:submissions)
  end

  def create
    @content = Form.find(params[:form_id]).contents.create(content_params)
  end

  def update
    @content = Content.find(params[:id])
    if @content.nil?
      render json: {message: 'Cannot find content'}, status: :not_found
    else 
      if @content.update(content_params)
        render json: {updated: true}, status: :success
      else
        render json: {updated: false}, status: :bad_request
      end
    end
  end

  def delete
    @content = Content.find(params[:id])
    if @content.nil?
      render json: {message: 'Cannot find content'}, status: :not_found
    else 
      if @content.destroy
        render json: {deleted: true}, status: :success
      else
        render json: {deleted: false}, status: :bad_request
      end
    end
  end

  private

  def content_params
    params.require(:content).permit(:type,:index,:label,:options)
{'fraction_non_alphanumeric': 0.11424180327868852, 'fraction_numerical': 0.0, 'mean_word_length': 3.5, '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': '3089946', 'n_tokens_mistral': 581, 'n_tokens_neox': 566, 'n_words': 156}