Skip to content

Instantly share code, notes, and snippets.

@airhorns
Created July 22, 2010 13:37
Show Gist options
  • Save airhorns/485971 to your computer and use it in GitHub Desktop.
Save airhorns/485971 to your computer and use it in GitHub Desktop.
Started GET "/product_categories/autocomplete_for_product_sub_category_name?q=ang&limit=10&timestamp=1279805094583" for 130.15.105.53 at 2010-07-22 09:29:55 -0400
Processing by ProductCategoriesController#autocomplete_for_product_sub_category_name as HTML
Parameters: {"q"=>"ang", "limit"=>"10", "timestamp"=>"1279805094583"}
Rendered inline template (0.6ms)
Completed 200 OK in 58ms (Views: 1.7ms | ActiveRecord: 7.7ms)
Started GET "/product_categories/autocomplete_for_product_sub_category_name?q=ang&limit=10&timestamp=1279805094583" for 130.15.105.53 at 2010-07-22 09:30:05 -0400
Processing by ProductCategoriesController#autocomplete_for_product_sub_category_name as HTML
Parameters: {"q"=>"ang", "limit"=>"10", "timestamp"=>"1279805094583"}
Completed in 14ms
NameError (uninitialized constant ProductSubCategory):
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/inflector/methods.rb:114:in `block in constantize'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/inflector/methods.rb:113:in `each'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/inflector/methods.rb:113:in `constantize'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/core_ext/string/conversions.rb:59:in `constantize'
/var/www/dowling/vendor/plugins/simple_auto_complete/lib/simple_autocomplete.rb:16:in `block in autocomplete_for'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/abstract_controller/base.rb:145:in `process_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal/rendering.rb:11:in `process_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:462:in `_run__205426859__process_action__709867094__callbacks'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:408:in `_run_process_action_callbacks'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:88:in `run_callbacks'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal/instrumentation.rb:29:in `block in process_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/notifications.rb:48:in `instrument'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal/instrumentation.rb:28:in `process_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal/rescue.rb:8:in `process_action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/abstract_controller/base.rb:114:in `process'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/abstract_controller/rendering.rb:40:in `process'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal.rb:126:in `dispatch'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_controller/metal.rb:166:in `block in action'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:27:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:27:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-mount-0.6.9/lib/rack/mount/route_set.rb:148:in `block in call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-mount-0.6.9/lib/rack/mount/code_generation.rb:89:in `block in recognize'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-mount-0.6.9/lib/rack/mount/code_generation.rb:66:in `optimized_each'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-mount-0.6.9/lib/rack/mount/code_generation.rb:88:in `recognize'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-mount-0.6.9/lib/rack/mount/route_set.rb:139:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:457:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/haml-3.0.10/lib/sass/plugin/rack.rb:41:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/warden-0.10.7/lib/warden/manager.rb:35:in `block in call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/warden-0.10.7/lib/warden/manager.rb:34:in `catch'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/warden-0.10.7/lib/warden/manager.rb:34:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/head.rb:14:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/flash.rb:177:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/session/abstract_store.rb:106:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/cookies.rb:235:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0.beta4/lib/active_record/query_cache.rb:31:in `block in call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0.beta4/lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0.beta4/lib/active_record/query_cache.rb:11:in `cache'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0.beta4/lib/active_record/query_cache.rb:30:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0.beta4/lib/active_record/connection_adapters/abstract/connection_pool.rb:365:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:414:in `_run_call_callbacks'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:88:in `run_callbacks'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/callbacks.rb:44:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-1.1.0/lib/rack/sendfile.rb:105:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/show_exceptions.rb:48:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.0.beta4/lib/rails/rack/logger.rb:14:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-1.1.0/lib/rack/runtime.rb:17:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-1.1.0/lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/rack-1.1.0/lib/rack/lock.rb:11:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.0.beta4/lib/rails/application.rb:145:in `call'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.0.beta4/lib/rails/application.rb:81:in `method_missing'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/rack/application_spawner.rb:120:in `run'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/rack/application_spawner.rb:65:in `block in spawn_application'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/utils.rb:252:in `safe_fork'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/rack/application_spawner.rb:58:in `spawn_application'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/rack/application_spawner.rb:41:in `spawn_application'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/spawn_manager.rb:150:in `spawn_application'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/spawn_manager.rb:278:in `handle_spawn_application'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
/home/hornairs/.rvm/gems/ruby-1.9.2-head/gems/passenger-2.2.15/bin/passenger-spawn-server:61:in `<main>'
class ProductCategoriesController < ApplicationController
before_filter :clean_autocomplete_name, :only => [:autocomplete_for_product_root_category_name, :autocomplete_for_product_sub_category_name]
cat_autocomplete = Proc.new do |cats|
cats.map{|cat| "#{cat.name_with_parents} --- #{cat.id}"}.join("\n")
end
autocomplete_for(:product_root_category, :name, :class => ProductCategory.where(:ancestors_count => 0), &cat_autocomplete)
autocomplete_for(:product_sub_category, :name, :class => ProductCategory.where(:ancestors_count => 1), &cat_autocomplete)
private
def clean_autocomplete_name
params[:q] = params[:q].split(/: /)[-1]
return true
end
end
module SimpleAutocomplete
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
end
# see Readme for details
class ActionController::Base
def self.autocomplete_for(name, method, options = {}, &block)
options = options.dup
define_method("autocomplete_for_#{name}_#{method}") do
methods = options.delete(:match) || [*method]
condition = methods.map{|m| "LOWER(#{m}) LIKE ?"} * " OR "
values = methods.map{|m| "%#{params[:q].to_s.downcase}%"}
conditions = [condition, *values]
model = options.delete(:class) || name
model = model.to_s.camelize.constantize if model.is_a?(Symbol)
find_options = {
:conditions => conditions,
:order => "#{methods.first} ASC",
:limit => 10
}.merge!(options)
@items = model.scoped(find_options)
out = if block_given?
instance_exec @items, &block
else
%Q[<%= @items.map {|item| h(item.#{methods.first})}.uniq.join("\n")%>]
end
render :inline => out
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment