<commit_before>class RecipeDetailsController < ApplicationController
  before_action :deny_spammers!, only: [:update]
  before_action :load_and_authorize_recipe!
  invisible_captcha only: [:create, :update], on_spam: :redirect_spammers!

  def show
    # Never cache this page to ensure browser reloads
    expires_now

    @details ||= RecipeDetail.create!(recipe_id: @recipe.id)
    @hops = @details.hops
    @fermentables = @details.fermentables
    @miscs = @details.miscs
    @yeasts = @details.yeasts
    @mash_steps = @details.mash_steps
    @style = @details.style
    @styles = Style.style_options(@style&.style_guide || 'SHBF 2018')

    respond_to do |format|
      format.html
      format.xml {
        send_data render_to_string(:show),
            filename: 'recipe.xml',
            type: 'application/xml',
            disposition: 'attachment'
      }
    end
  end

  def update
    respond_to do |format|
      if @details.update(details_params)
        format.html { redirect_to recipe_details_path }
        format.json { render json: @details, status: :ok, location: recipe_details_path }
        format.js { render layout: false, status: :ok, location: recipe_details_path }<commit_msg>Fix issue when creating a private recipe without beerxml<commit_after>class RecipeDetailsController < ApplicationController
  before_action :deny_spammers!, only: [:update]
  before_action :load_and_authorize_recipe!
  invisible_captcha only: [:create, :update], on_spam: :redirect_spammers!

  def show
    # Never cache this page to ensure browser reloads
    expires_now

    @details ||= RecipeDetail.create!(recipe: @recipe)
    @hops = @details.hops
    @fermentables = @details.fermentables
    @miscs = @details.miscs
    @yeasts = @details.yeasts
    @mash_steps = @details.mash_steps
    @style = @details.style
    @styles = Style.style_options(@style&.style_guide || 'SHBF 2018')

    respond_to do |format|
      format.html
      format.xml {
        send_data render_to_string(:show),
            filename: 'recipe.xml',
            type: 'application/xml',
            disposition: 'attachment'
      }
    end
  end

  def update
    respond_to do |format|
      if @details.update(details_params)
        format.html { redirect_to recipe_details_path }
        format.json { render json: @details, status: :ok, location: recipe_details_path }
        format.js { render layout: false, status: :ok, location: recipe_details_path }
{'fraction_non_alphanumeric': 0.0989010989010989, 'fraction_numerical': 0.003256003256003256, 'mean_word_length': 3.297202797202797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, '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': '4253876', 'n_tokens_mistral': 780, 'n_tokens_neox': 747, 'n_words': 180}