<commit_before>require 'gds_api/publishing_api_v2'

class DocumentsController < ApplicationController
  include ActionView::Context
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::TextHelper

  before_action :fetch_document, only: [:edit, :show, :publish, :update]
  before_action :permitted?, if: :document_type

  def index
    if current_format
      @documents = document_klass.all

      @documents.sort! { |a, b| a.public_updated_at <=> b.public_updated_at }.reverse!
    else
      redirect_to manuals_path
    end
  end

  def new
    @document = document_klass.new
  end

  def create
    @document = document_klass.new(
      filtered_params(params[current_format.format_name])
    )

    if @document.valid?
      if @document.save!
        flash[:success] = "Created #{@document.title}"
        redirect_to documents_path(current_format.document_type)
      else
        flash.now[:danger] = "There was an error creating #{@document.title}. Please try again later."
        render :new
      end
    else
      flash.now[:danger] = document_error_messages
      render :new, status: 422
    end
  end

  def show; end

  def edit; end

  def update
    new_params = filtered_params(params[current_format.format_name])

    new_params.each do |k, v|
      @document.public_send(:"#{k}=", v)
    end

    if @document.valid?
      if @document.save!
        flash[:success] = "Updated #{@document.title}"
        redirect_to documents_path(current_format.document_type)
      else
        flash.now[:danger] = "There was an error updating #{@document.title}. Please try again later."
        render :edit
      end
    else
      flash.now[:danger] = document_error_messages
      render :edit, status: 422
    end
  end

  def publish
    if @document.publish!
      flash[:success] = "Published #{@document.title}"
      redirect_to documents_path(current_format.document_type)
    else
      flash[:danger] = "There was an error publishing #{@document.title}. Please try again later."
      redirect_to document_path(current_format.document_type, params[:content_id])
    end
  end
<commit_msg>Redirect to show page on create/update/publish.<commit_after>require 'gds_api/publishing_api_v2'

class DocumentsController < ApplicationController
  include ActionView::Context
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::TextHelper

  before_action :fetch_document, only: [:edit, :show, :publish, :update]
  before_action :permitted?, if: :document_type

  def index
    if current_format
      @documents = document_klass.all

      @documents.sort! { |a, b| a.public_updated_at <=> b.public_updated_at }.reverse!
    else
      redirect_to manuals_path
    end
  end

  def new
    @document = document_klass.new
  end

  def create
    @document = document_klass.new(
      filtered_params(params[current_format.format_name])
    )

    if @document.valid?
      if @document.save!
        flash[:success] = "Created #{@document.title}"
        redirect_to document_path(current_format.document_type, @document.content_id)
      else
        flash.now[:danger] = "There was an error creating #{@document.title}. Please try again later."
        render :new
      end
    else
      flash.now[:danger] = document_error_messages
      render :new, status: 422
    end
  end

  def show; end

  def edit; end

  def update
    new_params = filtered_params(params[current_format.format_name])

    new_params.each do |k, v|
      @document.public_send(:"#{k}=", v)
    end

    if @document.valid?
      if @document.save!
        flash[:success] = "Updated #{@document.title}"
        redirect_to document_path(current_format.document_type, @document.content_id)
      else
        flash.now[:danger] = "There was an error updating #{@document.title}. Please try again later."
        render :edit
      end
    else
      flash.now[:danger] = document_error_messages
      render :edit, status: 422
    end
  end

  def publish
    if @document.publish!
      flash[:success] = "Published #{@document.title}"
    else
      flash[:danger] = "There was an error publishing #{@document.title}. Please try again later."
    end
    redirect_to document_path(current_format.document_type, params[:content_id])
  end

{'fraction_non_alphanumeric': 0.10063187456119822, 'fraction_numerical': 0.003276386613620407, 'mean_word_length': 3.1984282907662083, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6525972', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1266, 'n_words': 321}