rails3-jquery-autocomplete 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +46 -35
- data/README.markdown +26 -3
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/rails3-jquery-autocomplete.rb +2 -2
- data/rails3-jquery-autocomplete.gemspec +5 -2
- data/test/controller_module_test.rb +17 -0
- metadata +22 -6
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,34 +2,34 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
abstract (1.0.0)
|
5
|
-
actionmailer (3.0.0
|
6
|
-
actionpack (= 3.0.0
|
5
|
+
actionmailer (3.0.0)
|
6
|
+
actionpack (= 3.0.0)
|
7
7
|
mail (~> 2.2.5)
|
8
|
-
actionpack (3.0.0
|
9
|
-
activemodel (= 3.0.0
|
10
|
-
activesupport (= 3.0.0
|
8
|
+
actionpack (3.0.0)
|
9
|
+
activemodel (= 3.0.0)
|
10
|
+
activesupport (= 3.0.0)
|
11
11
|
builder (~> 2.1.2)
|
12
12
|
erubis (~> 2.6.6)
|
13
13
|
i18n (~> 0.4.1)
|
14
14
|
rack (~> 1.2.1)
|
15
|
-
rack-mount (~> 0.6.
|
15
|
+
rack-mount (~> 0.6.12)
|
16
16
|
rack-test (~> 0.5.4)
|
17
|
-
tzinfo (~> 0.3.
|
18
|
-
activemodel (3.0.0
|
19
|
-
activesupport (= 3.0.0
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.0)
|
19
|
+
activesupport (= 3.0.0)
|
20
20
|
builder (~> 2.1.2)
|
21
21
|
i18n (~> 0.4.1)
|
22
|
-
activerecord (3.0.0
|
23
|
-
activemodel (= 3.0.0
|
24
|
-
activesupport (= 3.0.0
|
25
|
-
arel (~> 0.
|
26
|
-
tzinfo (~> 0.3.
|
27
|
-
activeresource (3.0.0
|
28
|
-
activemodel (= 3.0.0
|
29
|
-
activesupport (= 3.0.0
|
30
|
-
activesupport (3.0.0
|
31
|
-
arel (0.
|
32
|
-
activesupport (
|
22
|
+
activerecord (3.0.0)
|
23
|
+
activemodel (= 3.0.0)
|
24
|
+
activesupport (= 3.0.0)
|
25
|
+
arel (~> 1.0.0)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.0)
|
28
|
+
activemodel (= 3.0.0)
|
29
|
+
activesupport (= 3.0.0)
|
30
|
+
activesupport (3.0.0)
|
31
|
+
arel (1.0.1)
|
32
|
+
activesupport (~> 3.0.0)
|
33
33
|
builder (2.1.2)
|
34
34
|
erubis (2.6.6)
|
35
35
|
abstract (>= 1.0.0)
|
@@ -48,36 +48,47 @@ GEM
|
|
48
48
|
mime-types (1.16)
|
49
49
|
polyglot (0.3.1)
|
50
50
|
rack (1.2.1)
|
51
|
-
rack-mount (0.6.
|
51
|
+
rack-mount (0.6.12)
|
52
52
|
rack (>= 1.0.0)
|
53
53
|
rack-test (0.5.4)
|
54
54
|
rack (>= 1.0)
|
55
|
-
rails (3.0.0
|
56
|
-
actionmailer (= 3.0.0
|
57
|
-
actionpack (= 3.0.0
|
58
|
-
activerecord (= 3.0.0
|
59
|
-
activeresource (= 3.0.0
|
60
|
-
activesupport (= 3.0.0
|
61
|
-
bundler (
|
62
|
-
railties (= 3.0.0
|
63
|
-
railties (3.0.0
|
64
|
-
actionpack (= 3.0.0
|
65
|
-
activesupport (= 3.0.0
|
66
|
-
rake (>= 0.8.
|
55
|
+
rails (3.0.0)
|
56
|
+
actionmailer (= 3.0.0)
|
57
|
+
actionpack (= 3.0.0)
|
58
|
+
activerecord (= 3.0.0)
|
59
|
+
activeresource (= 3.0.0)
|
60
|
+
activesupport (= 3.0.0)
|
61
|
+
bundler (~> 1.0.0)
|
62
|
+
railties (= 3.0.0)
|
63
|
+
railties (3.0.0)
|
64
|
+
actionpack (= 3.0.0)
|
65
|
+
activesupport (= 3.0.0)
|
66
|
+
rake (>= 0.8.4)
|
67
67
|
thor (~> 0.14.0)
|
68
68
|
rake (0.8.7)
|
69
|
+
reek (1.2.8)
|
70
|
+
ruby2ruby (~> 1.2)
|
71
|
+
ruby_parser (~> 2.0)
|
72
|
+
sexp_processor (~> 3.0)
|
73
|
+
ruby2ruby (1.2.4)
|
74
|
+
ruby_parser (~> 2.0)
|
75
|
+
sexp_processor (~> 3.0)
|
76
|
+
ruby_parser (2.0.4)
|
77
|
+
sexp_processor (~> 3.0)
|
69
78
|
rubyforge (2.0.4)
|
70
79
|
json_pure (>= 1.1.7)
|
80
|
+
sexp_processor (3.0.4)
|
71
81
|
sqlite3-ruby (1.3.1)
|
72
82
|
thor (0.14.0)
|
73
83
|
treetop (1.4.8)
|
74
84
|
polyglot (>= 0.3.1)
|
75
|
-
tzinfo (0.3.
|
85
|
+
tzinfo (0.3.23)
|
76
86
|
|
77
87
|
PLATFORMS
|
78
88
|
ruby
|
79
89
|
|
80
90
|
DEPENDENCIES
|
81
91
|
jeweler
|
82
|
-
rails (= 3.0.0
|
92
|
+
rails (= 3.0.0)
|
93
|
+
reek
|
83
94
|
sqlite3-ruby
|
data/README.markdown
CHANGED
@@ -62,14 +62,16 @@ This will create an action _autocomplete_brand_name_ on your controller, don't f
|
|
62
62
|
get :autocomplete_brand_name, :on => :collection
|
63
63
|
end
|
64
64
|
|
65
|
+
### Options
|
66
|
+
|
67
|
+
#### :full => true
|
68
|
+
|
65
69
|
By default, the search starts from the beginning of the string you're searching for. If you want to do a full search, set the _full_ parameter to true.
|
66
70
|
|
67
71
|
class ProductsController < Admin::BaseController
|
68
72
|
autocomplete :brand, :name, :full => true
|
69
73
|
end
|
70
74
|
|
71
|
-
#### :full => true
|
72
|
-
|
73
75
|
The following terms would match the query 'un':
|
74
76
|
|
75
77
|
* Luna
|
@@ -82,6 +84,27 @@ Only the following terms mould match the query 'un':
|
|
82
84
|
|
83
85
|
* Unacceptable
|
84
86
|
|
87
|
+
#### :display_value
|
88
|
+
|
89
|
+
If you want to display a different version of what you're looking for, you can use the :display_value option.
|
90
|
+
|
91
|
+
This options receives a method name as the parameter, and that method will be called on the instance when displaying the results.
|
92
|
+
|
93
|
+
class Brand < ActiveRecord::Base
|
94
|
+
def funky_method
|
95
|
+
"#{self.name}.camelize"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
class ProductsController < Admin::BaseController
|
101
|
+
autocomplete :brand, :name, :display_value => :funky_method
|
102
|
+
end
|
103
|
+
|
104
|
+
In the example above, you will search by _name_, but the autocomplete list will display the result of _funky_method_
|
105
|
+
|
106
|
+
This wouldn't really make much sense unless you use it with the :id_element HTML tag. (See below)
|
107
|
+
|
85
108
|
### View
|
86
109
|
|
87
110
|
On your view, all you have to do is include the attribute autocomplete on the text field
|
@@ -110,7 +133,7 @@ If you want to make changes to the gem, first install bundler 1.0.0:
|
|
110
133
|
|
111
134
|
gem install bundler --pre
|
112
135
|
|
113
|
-
And then, install all your
|
136
|
+
And then, install all your dependencies:
|
114
137
|
|
115
138
|
bundle install
|
116
139
|
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.email = "david.padilla@crowdint.com"
|
11
11
|
gem.homepage = "http://github.com/crowdint/rails3-jquery-autocomplete"
|
12
12
|
gem.authors = ["David Padilla"]
|
13
|
-
|
13
|
+
gem.add_development_dependency "rails", ">= 3.0.0.rc2"
|
14
14
|
end
|
15
15
|
Jeweler::GemcutterTasks.new
|
16
16
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -35,14 +35,14 @@ module Rails3JQueryAutocomplete
|
|
35
35
|
items = {}
|
36
36
|
end
|
37
37
|
|
38
|
-
render :json => json_for_autocomplete(items, method)
|
38
|
+
render :json => json_for_autocomplete(items, (options[:display_value] ? options[:display_value] : method))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
44
|
def json_for_autocomplete(items, method)
|
45
|
-
items.collect {|i| {"id" => i.id, "label" => i
|
45
|
+
items.collect {|i| {"id" => i.id, "label" => i.send(method), "value" => i.send(method)}}
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails3-jquery-autocomplete}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Padilla"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-31}
|
13
13
|
s.description = %q{Use jQuery's autocomplete plugin with Rails 3.}
|
14
14
|
s.email = %q{david.padilla@crowdint.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -49,9 +49,12 @@ Gem::Specification.new do |s|
|
|
49
49
|
s.specification_version = 3
|
50
50
|
|
51
51
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rails>, [">= 3.0.0.rc2"])
|
52
53
|
else
|
54
|
+
s.add_dependency(%q<rails>, [">= 3.0.0.rc2"])
|
53
55
|
end
|
54
56
|
else
|
57
|
+
s.add_dependency(%q<rails>, [">= 3.0.0.rc2"])
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
@@ -11,6 +11,9 @@ class Actor < ActiveRecord::Base
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Movie < ActiveRecord::Base
|
14
|
+
def display_name
|
15
|
+
"Movie: #{name}"
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
19
|
def setup_db
|
@@ -117,4 +120,18 @@ class ActorsControllerTest < ActionController::TestCase
|
|
117
120
|
assert_equal(json_response.length, 1)
|
118
121
|
assert_equal(json_response.first["label"], 'aLpHa')
|
119
122
|
end
|
123
|
+
|
124
|
+
def test_value_option
|
125
|
+
ActorsController.send(:autocomplete, :movie, :name, {:display_value => :display_name})
|
126
|
+
|
127
|
+
@movie = Movie.create(:name => 'Alpha')
|
128
|
+
|
129
|
+
get :autocomplete_movie_name, :term => 'Al'
|
130
|
+
|
131
|
+
json_response = JSON.parse(@response.body)
|
132
|
+
|
133
|
+
assert_equal(@movie.display_name, json_response.first["label"])
|
134
|
+
assert_equal(@movie.display_name, json_response.first["value"])
|
135
|
+
assert_equal(@movie.id, json_response.first["id"])
|
136
|
+
end
|
120
137
|
end
|
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Padilla
|
@@ -15,10 +15,26 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-31 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 977940607
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
- rc2
|
35
|
+
version: 3.0.0.rc2
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id001
|
22
38
|
description: Use jQuery's autocomplete plugin with Rails 3.
|
23
39
|
email: david.padilla@crowdint.com
|
24
40
|
executables: []
|