autosuggest-rb 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +7 -2
- data/lib/autosuggest/controller_macros.rb +3 -8
- data/lib/autosuggest/helpers.rb +4 -0
- data/lib/autosuggest/version.rb +1 -1
- metadata +2 -2
data/README.markdown
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# autosuggest-rb
|
2
2
|
|
3
|
+
## Summary
|
4
|
+
|
5
|
+
This gem wraps the jQuery autoSuggest plugin and provides helpers to make it easy to use in rails. It supports ActiveRecord, Mongoid, and MongoMapper. This was influenced by crowdint's rails3-jquery-autocomplete gem.
|
6
|
+
|
3
7
|
## Installing
|
4
8
|
|
5
9
|
Include the gem on your Gemfile
|
@@ -34,7 +38,7 @@ Assuming you have a Tag model:
|
|
34
38
|
|
35
39
|
### Controller
|
36
40
|
|
37
|
-
Your
|
41
|
+
Your controller will need an action to respond to the autosuggest textfield. To add it to your controller call the autosuggest method and pass it the name of the model and column name as in the following example:
|
38
42
|
|
39
43
|
class RecipesController < ApplicationController
|
40
44
|
autosuggest :tag, :name
|
@@ -71,7 +75,8 @@ But you can pass options in by using the autosuggest_options param
|
|
71
75
|
|
72
76
|
f.autosuggest_field :tags, autosuggest_tag_name_recipes_path, :autosuggest_options => {"neverSubmit" => "true"}
|
73
77
|
|
74
|
-
|
78
|
+
|
79
|
+
Here are the other options you can pass in:
|
75
80
|
|
76
81
|
**asHtmlName:** string (false by default) - Enables you to specify your own custom name that will be attributed to the text field
|
77
82
|
|
@@ -7,20 +7,15 @@ module Autosuggest
|
|
7
7
|
# get :autosuggest_brand_name, :on => :collection
|
8
8
|
# end
|
9
9
|
def autosuggest(object, name, options={})
|
10
|
-
display_name = options[:display] || name
|
11
|
-
order = options[:order] || "#{name} ASC"
|
12
|
-
limit = options[:limit] || 10
|
13
|
-
like_clause = defined?(PGconn) ? 'ILIKE' : 'LIKE'
|
14
|
-
|
15
10
|
options[:display] ||= name
|
16
11
|
options[:order] ||= "#{name} ASC"
|
17
12
|
options[:limit] ||= 10
|
18
|
-
options[:like_clause] = defined?(PGconn) ? 'ILIKE' : 'LIKE'
|
19
13
|
options[:name] = name
|
20
14
|
|
21
15
|
define_method "autosuggest_#{object}_#{name}" do
|
22
|
-
|
23
|
-
|
16
|
+
options.merge!(:query => params[:query], :object => objectify(object), :like_clause => resolve_like_clause)
|
17
|
+
results = db_store(object).query(options)
|
18
|
+
render :json => Yajl::Encoder.encode(results.map{|r| {:name => r.send(options[:display]), :value => r.id}})
|
24
19
|
end
|
25
20
|
end
|
26
21
|
end
|
data/lib/autosuggest/helpers.rb
CHANGED
data/lib/autosuggest/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: autosuggest-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Derrick Camerino
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-05 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|