rails3-jquery-autocomplete 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,13 +4,13 @@ An easy way to use jQuery's autocomplete with Rails 3
4
4
 
5
5
  ## Before you start
6
6
 
7
- Make sure your project is using jQuery and you have the Autocomplete plugin installed
7
+ Make sure your project is using jQuery-ui with the autocomplete widget
8
8
  before you continue.
9
9
 
10
10
  You can find more info about that here:
11
11
 
12
12
  * http://jquery.com/
13
- * http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
13
+ * http://jqueryui.com/demos/autocomplete/
14
14
  * http://github.com/rails/jquery-ujs
15
15
 
16
16
  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
19
19
 
20
20
  Include the gem on your Gemfile
21
21
 
22
- gem 'rails3-jquery-autocomplete', '>= 0.0.3', :require => 'autocomplete'
22
+ gem 'rails3-jquery-autocomplete', '>= 0.1.0', :require => 'autocomplete'
23
23
 
24
24
  Install it
25
25
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('rails3-jquery-autocomplete', '0.0.3') do |p|
5
+ Echoe.new('rails3-jquery-autocomplete', '0.1.0') do |p|
6
6
  p.description = "Use jQuery's autocomplete plugin with Rails 3."
7
7
  p.url = "http://github.com/crowdint/rails3-jquery-autocomplete"
8
8
  p.author = "David Padilla"
@@ -31,16 +31,21 @@ module Autocomplete
31
31
  order = options[:order] || "#{method} ASC"
32
32
 
33
33
  define_method("autocomplete_#{object}_#{method}") do
34
- unless params[:q] && params[:q].empty?
35
- items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{params[:q]}%"]).limit(limit).order(order)
34
+ unless params[:term] && params[:term].empty?
35
+ items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{params[:term]}%"]).limit(limit).order(order)
36
36
  else
37
- items = []
37
+ items = {}
38
38
  end
39
39
 
40
- render :text => items.collect {|i| i[method]}.join("\n")
40
+ render :json => json_for_autocomplete(items, method)
41
41
  end
42
42
  end
43
43
  end
44
+
45
+ private
46
+ def json_for_autocomplete(items, method)
47
+ items.collect {|i| {"id" => i.id, "label" => i[method], "value" => i[method]}}
48
+ end
44
49
  end
45
50
 
46
51
  class ActionController::Base
@@ -11,6 +11,8 @@
11
11
 
12
12
  $(document).ready(function(){
13
13
  $('input[autocomplete]').each(function(i){
14
- $(this).autocomplete($(this).attr('autocomplete'));
14
+ $(this).autocomplete({
15
+ source: $(this).attr('autocomplete')
16
+ });
15
17
  });
16
- });
18
+ });
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rails3-jquery-autocomplete}
5
- s.version = "0.0.3"
5
+ s.version = "0.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["David Padilla"]
9
- s.date = %q{2010-07-13}
9
+ s.date = %q{2010-07-15}
10
10
  s.description = %q{Use jQuery's autocomplete plugin with Rails 3.}
11
11
  s.email = %q{david@crowdint.com}
12
12
  s.extra_rdoc_files = ["README.markdown", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails3-jquery-autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 0.0.3
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Padilla
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-13 00:00:00 -05:00
18
+ date: 2010-07-15 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21