<commit_before>class BoardsController < ApplicationController
  before_action :authenticate_user!, only: [:new]
  #before_save { |user| user.name = user.name.downcase }

  def new
    @board = Board.new
    @user = current_user
  end

  def create
    
    hash = board_params["links_attributes"]
    valid_links = hash.reject{|k, v| v["url"] == ""}
    final_hash = {}
    final_hash["name"] = board_params["name"]
    final_hash["user_id"] = board_params["user_id"]
    final_hash["links_attributes"] = valid_links
    final_hash["tags_attributes"] = board_params["tags_attributes"]
    @board = Board.create(final_hash)
    redirect_to @board
  end

  def search
    filter = params[:search_term]
    @search_term = params[:search_term].downcase
    @boards = Board.joins(:tags).where('tags.name' => filter).limit(9)
  end

  def index
    @boards = Board.order(views: :desc).limit(9)
  end

  def add_to_library
    @board = Board.find_or_create_by(user_id: "#{current_user.id}", name: "My Library")
    @link = Link.find(params["linkID"])
    @link.boards << @board
    message = "Added to your library"
    respond_to do |format|
      format.html {redirect_to @board}
      format.json {render json: {message: message}}
    end
  end

  def library
    @board = Board.find_or_create_by(user_id: "#{current_user.id}", name: "My Library")
    @web_links = @board.links.where(kind: [1,2,3,4]) 
    @text = @board.links.where(kind: 5)
    @current_user = current_user
  end

  def filter
    filter = params[:filter_by]
    filtered_boards = Board.joins(:tags).where('tags.name' => filter).limit(9)
    boards_array = filtered_boards.map do |board|
      {id: board.id, name: board.name} <commit_msg>fixed search<commit_after>class BoardsController < ApplicationController
  before_action :authenticate_user!, only: [:new]
  #before_save { |user| user.name = user.name.downcase }

  def new
    @board = Board.new
    @user = current_user
  end

  def create
    
    hash = board_params["links_attributes"]
    valid_links = hash.reject{|k, v| v["url"] == ""}
    final_hash = {}
    final_hash["name"] = board_params["name"]
    final_hash["user_id"] = board_params["user_id"]
    final_hash["links_attributes"] = valid_links
    final_hash["tags_attributes"] = board_params["tags_attributes"]
    @board = Board.create(final_hash)
    redirect_to @board
  end

  def search
    filter = params[:search_term].downcase
    @search_term = params[:search_term].downcase
    @boards = Board.joins(:tags).where('tags.name' => filter).limit(9)
  end

  def index
    @boards = Board.order(views: :desc).limit(9)
  end

  def add_to_library
    @board = Board.find_or_create_by(user_id: "#{current_user.id}", name: "My Library")
    @link = Link.find(params["linkID"])
    @link.boards << @board
    message = "Added to your library"
    respond_to do |format|
      format.html {redirect_to @board}
      format.json {render json: {message: message}}
    end
  end

  def library
    @board = Board.find_or_create_by(user_id: "#{current_user.id}", name: "My Library")
    @web_links = @board.links.where(kind: [1,2,3,4]) 
    @text = @board.links.where(kind: 5)
    @current_user = current_user
  end

  def filter
    binding.pry
    filter = params[:filter_by]
    filtered_boards = Board.joins(:tags).where('tags.name' => filter).limit(9)
    boards_array = filtered_boards.map do |board|
      {id: board.id, name: board.name} 
{'fraction_non_alphanumeric': 0.13994169096209913, 'fraction_numerical': 0.004664723032069971, 'mean_word_length': 3.7455048409405256, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '506908', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1150, 'n_words': 238}