Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated to use jQuery-ui autocomplete widget

  • Loading branch information...
commit bb4c455917a67b01d988046113845928e0bd7af1 1 parent ef60d16
David Padilla authored
View
6 README.markdown
@@ -4,13 +4,13 @@ An easy way to use jQuery's autocomplete with Rails 3
## Before you start
-Make sure your project is using jQuery and you have the Autocomplete plugin installed
+Make sure your project is using jQuery-ui with the autocomplete widget
before you continue.
You can find more info about that here:
* http://jquery.com/
-* http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
+* http://jqueryui.com/demos/autocomplete/
* http://github.com/rails/jquery-ujs
I'd recommend you understand what's happening with those 3 tools before attempting to use this gem.
@@ -19,7 +19,7 @@ I'd recommend you understand what's happening with those 3 tools before attempti
Include the gem on your Gemfile
- gem 'rails3-jquery-autocomplete', '>= 0.0.3', :require => 'autocomplete'
+ gem 'rails3-jquery-autocomplete', '>= 0.1.0', :require => 'autocomplete'
Install it
View
2  Rakefile
@@ -2,7 +2,7 @@ require 'rubygems'
require 'rake'
require 'echoe'
-Echoe.new('rails3-jquery-autocomplete', '0.0.3') do |p|
+Echoe.new('rails3-jquery-autocomplete', '0.1.0') do |p|
p.description = "Use jQuery's autocomplete plugin with Rails 3."
p.url = "http://github.com/crowdint/rails3-jquery-autocomplete"
p.author = "David Padilla"
View
13 lib/autocomplete.rb
@@ -31,16 +31,21 @@ def autocomplete(object, method, options = {})
order = options[:order] || "#{method} ASC"
define_method("autocomplete_#{object}_#{method}") do
- unless params[:q] && params[:q].empty?
- items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{params[:q]}%"]).limit(limit).order(order)
+ unless params[:term] && params[:term].empty?
+ items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{params[:term]}%"]).limit(limit).order(order)
else
- items = []
+ items = {}
end
- render :text => items.collect {|i| i[method]}.join("\n")
+ render :json => json_for_autocomplete(items, method)
end
end
end
+
+ private
+ def json_for_autocomplete(items, method)
+ items.collect {|i| {"id" => i.id, "label" => i[method], "value" => i[method]}}
+ end
end
class ActionController::Base
View
6 lib/generators/templates/autocomplete-rails.js
@@ -11,6 +11,8 @@
$(document).ready(function(){
$('input[autocomplete]').each(function(i){
- $(this).autocomplete($(this).attr('autocomplete'));
+ $(this).autocomplete({
+ source: $(this).attr('autocomplete')
+ });
});
-});
+});
View
30 rails3-jquery-autocomplete.gemspec
@@ -0,0 +1,30 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{rails3-jquery-autocomplete}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
+ s.authors = ["David Padilla"]
+ s.date = %q{2010-07-15}
+ s.description = %q{Use jQuery's autocomplete plugin with Rails 3.}
+ s.email = %q{david@crowdint.com}
+ s.extra_rdoc_files = ["README.markdown", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js"]
+ s.files = ["README.markdown", "Rakefile", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js", "Manifest", "rails3-jquery-autocomplete.gemspec"]
+ s.homepage = %q{http://github.com/crowdint/rails3-jquery-autocomplete}
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rails3-jquery-autocomplete", "--main", "README.markdown"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{rails3-jquery-autocomplete}
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Use jQuery's autocomplete plugin with Rails 3.}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.