idris-auto_complete_jquery 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "auto_complete_jquery"
3
- s.version = "0.1.0"
3
+ s.version = "0.1.1"
4
4
  s.date = "2008-12-28"
5
5
  s.summary = "auto-complete method for Rails controllers using Dylan Verheul's jQuery autocomplete plugin"
6
6
  s.email = "chris@cobaltedge.com"
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  "Rakefile",
14
14
  "auto_complete_jquery.gemspec",
15
15
  "init.rb",
16
- "lib/quto_complete_jquery.rb"]
16
+ "lib/auto_complete_jquery.rb"]
17
17
  s.rdoc_options = ["--main", "README.txt"]
18
18
  s.extra_rdoc_files = ["CHANGELOG", "README"]
19
- end
19
+ end
@@ -0,0 +1,50 @@
1
+ module AutoCompleteJquery
2
+
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ #
8
+ # Example:
9
+ #
10
+ # # Controller
11
+ # class BlogController < ApplicationController
12
+ # auto_complete_for :post, :title
13
+ # end
14
+ #
15
+ # # View
16
+ # <%= text_field_with_auto_complete :post, title %>
17
+ #
18
+ # By default, auto_complete_for limits the results to 10 entries,
19
+ # and sorts by the given field.
20
+ #
21
+ # auto_complete_for takes a third parameter, an options hash to
22
+ # the find method used to search for the records:
23
+ #
24
+ # auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC'
25
+ #
26
+ # For help on defining text input fields with autocompletion,
27
+ # see ActionView::Helpers::JavaScriptHelper.
28
+ #
29
+ # For more on jQuery auto-complete, see the docs for the jQuery autocomplete
30
+ # plugin used in conjunction with this plugin:
31
+ # * http://www.dyve.net/jquery/?autocomplete
32
+ module ClassMethods
33
+ def auto_complete_for(object, method, options = {})
34
+ define_method("auto_complete_for_#{object}_#{method}") do
35
+ object_constant = object.to_s.camelize.constantize
36
+
37
+ find_options = {
38
+ :conditions => [ "LOWER(#{method}) LIKE ?", '%' + params[:q].downcase + '%' ],
39
+ :order => "#{method} ASC",
40
+ :select => "#{object_constant.table_name}.#{method}",
41
+ :limit => 10 }.merge!(options)
42
+
43
+ @items = object_constant.find(:all, find_options).collect(&method)
44
+
45
+ render :text => @items.join("\n")
46
+ end
47
+ end
48
+ end
49
+
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idris-auto_complete_jquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Bailey
@@ -28,7 +28,7 @@ files:
28
28
  - Rakefile
29
29
  - auto_complete_jquery.gemspec
30
30
  - init.rb
31
- - lib/quto_complete_jquery.rb
31
+ - lib/auto_complete_jquery.rb
32
32
  has_rdoc: true
33
33
  homepage: http://github.com/mojombo/grit
34
34
  post_install_message: