<commit_before>class CategoriesController < ApplicationController

before_action :authorize_user, only: [:new, :create]


  def index
    @categories = Category.find_each
  end
  
  
  def show
    @category = Category.find(params[:id])
  end
  
  def new
    @book = Book.find(params[:book_id])
    @category = Category.new
  end
  
  def create
    @book = Book.find(params[:book_id])
    @category = @book.categories.build(category_params)
    @book.save ? redirect_to(book_path(@book)) : render('new')
  end
  
  private 
  
  def category_params
    params.require(:category).permit(:name, :classification)
  end<commit_msg>Fix Add Category for books#show<commit_after>class CategoriesController < ApplicationController

before_action :authorize_user, only: [:new, :create]


  def index
    @categories = Category.find_each
  end
  
  
  def show
    @category = Category.find(params[:id])
  end
  
  def new
    @book = Book.find(params[:book_id])
    @category = Category.new
  end
  
  def create
    binding.pry
    @book = Book.find(params[:book_id])
    @category = @book.categories.build(category_params)
    @category.classification = @book.classification
    @book.save ? redirect_to(book_path(@book)) : render('new')
  end
  
  private 
  
  def category_params
    params.require(:category).permit(:name, :classification)
  end
{'fraction_non_alphanumeric': 0.11235119047619048, 'fraction_numerical': 0.0, 'mean_word_length': 3.6379310344827585, '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': '1200605', 'n_tokens_mistral': 438, 'n_tokens_neox': 427, 'n_words': 88}