<commit_before>
get '/questions/:question_id/recipes/new' do
  @question = Question.find_by(id: params[:question_id])
  @user_id = session[:user]
  erb :'recipes/new'
end

post '/questions/:question_id/recipes' do
  # TODO: clean this noise - use recipe hash inside params?
  recipe = Recipe.new(question_id: params[:question_id], user_id: params[:user_id], body: params[:recipe_body], best_answer: false)
  if recipe.save
    redirect "/questions/#{params[:question_id]}/recipes/#{recipe.id}"
  else
    @errors = recipe.errors.full_messages
    erb :'recipes/new'
  end
  # redirect or show previous with errors
end

get '/questions/:question_id/recipes/:recipe_id' do
  @recipe = Recipe.find_by(id: params[:recipe_id])
  @question = Question.find_by(id: params[:question_id])

  @comments = Comment.where(commentable_id: params[:recipe_id], commentable_type: 'Recipe')
  erb :'recipes/show'
end

get '/questions/:question_id/recipes/:recipe_id/edit' do
  @recipe = Recipe.find_by(id: params[:recipe_id])
  @question = Question.find_by(id: params[:question_id])
  erb :'recipes/edit'
end

put '/questions/:question_id/recipes/:recipe_id' do<commit_msg>Show 404 when user hardcodes nonexistant recipe page<commit_after>
get '/questions/:question_id/recipes/new' do
  @question = Question.find_by(id: params[:question_id])
  @user_id = session[:user]
  erb :'recipes/new'
end

post '/questions/:question_id/recipes' do
  # TODO: clean this noise - use recipe hash inside params?
  recipe = Recipe.new(question_id: params[:question_id], user_id: params[:user_id], body: params[:recipe_body], best_answer: false)
  if recipe.save
    redirect "/questions/#{params[:question_id]}/recipes/#{recipe.id}"
  else
    @errors = recipe.errors.full_messages
    erb :'recipes/new'
  end
  # redirect or show previous with errors
end

get '/questions/:question_id/recipes/:recipe_id' do
  @recipe = Recipe.find_by(id: params[:recipe_id])
  @question = Question.find_by(id: params[:question_id])
  @comments = Comment.where(commentable_id: params[:recipe_id], commentable_type: 'Recipe')
  if @recipe && @question
    erb :'recipes/show'
  else
    erb :'_404'
  end
end

get '/questions/:question_id/recipes/:recipe_id/edit' do
  @recipe = Recipe.find_by(id: params[:recipe_id])
  @question = Question.find_by(id: params[:question_id])
  if @recipe && @question
    erb :'recipes/edit'
  else
    erb :'_404'
  end
end

put '/questions/:question_id/recipes/:recipe_id' do
{'fraction_non_alphanumeric': 0.14065040650406505, 'fraction_numerical': 0.003658536585365854, 'mean_word_length': 4.987834549878346, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3502702', 'n_tokens_mistral': 887, 'n_tokens_neox': 883, 'n_words': 184}