<commit_before>class FavouritesController < ApplicationController
  
  before_filter :login_required

  cache_sweeper :favourites_sweeper,:only=>[:add,:delete]
  
  def add
    if params[:id]=="drag_search" #needs to creat the SavedSearch resource first
      saved_search = SavedSearch.new(:user_id => current_user.id, :search_query => params[:search_query], :search_type => params[:search_type])
      if SavedSearch.find_by_user_id_and_search_query_and_search_type(current_user,params[:search_query],params[:search_type]).nil? && saved_search.save
        resource=saved_search
      end
    else
      split_id=params[:id].split("_")
      resource = eval(split_id[1]).find_by_id(split_id[2].to_i)
    end
    
    f=Favourite.new
    f.user=current_user
    f.resource = resource
        
    if resource && resource.is_favouritable? && Favourite.find_by_user_id_and_resource_type_and_resource_id(current_user,f.resource_type,f.resource_id).nil? && f.save
      render :update, :status=>:created do |page|
          page.replace_html "favourite_list", :partial=>"favourites/gadget_list"
          page.visual_effect :highlight, "drop_favourites", :startcolor=>"#DDDDFF"
      end<commit_msg>switch from eval to constantize<commit_after>class FavouritesController < ApplicationController
  
  before_filter :login_required

  cache_sweeper :favourites_sweeper,:only=>[:add,:delete]
  
  def add
    if params[:id]=="drag_search" #needs to creat the SavedSearch resource first
      saved_search = SavedSearch.new(:user_id => current_user.id, :search_query => params[:search_query], :search_type => params[:search_type])
      if SavedSearch.find_by_user_id_and_search_query_and_search_type(current_user,params[:search_query],params[:search_type]).nil? && saved_search.save
        resource=saved_search
      end
    else
      split_id=params[:id].split("_")
      resource = split_id[1].constantize.find_by_id(split_id[2].to_i)
    end
    
    f=Favourite.new
    f.user=current_user
    f.resource = resource
        
    if resource && resource.is_favouritable? && Favourite.find_by_user_id_and_resource_type_and_resource_id(current_user,f.resource_type,f.resource_id).nil? && f.save
      render :update, :status=>:created do |page|
          page.replace_html "favourite_list", :partial=>"favourites/gadget_list"
          page.visual_effect :highlight, "drop_favourites", :startcolor=>"#DDDDFF"
      end
{'fraction_non_alphanumeric': 0.11216887417218543, 'fraction_numerical': 0.0016556291390728477, 'mean_word_length': 4.620930232558139, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6633019', 'n_tokens_mistral': 821, 'n_tokens_neox': 794, 'n_words': 117}