blob: 606f43b350ff041ce52b6fa492de84c684f28274 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
module ActionController
# Example:
#
# # Controller
# class BlogController < ApplicationController
# auto_complete_for :post, :title
# end
#
# # View
# <%= text_field_with_auto_complete :post, title %>
module AutoComplete
def self.append_features(base) #:nodoc:
super
base.extend(ClassMethods)
end
module ClassMethods
def auto_complete_for(object, method)
define_method("auto_complete_for_#{object}_#{method}") do
@items = object.to_s.camelize.constantize.find(
:all,
:conditions => [ "LOWER(#{method}) LIKE ?", '%' + request.raw_post.downcase + '%' ],
:order => "#{method} ASC"
)
render :inline => "<%= auto_complete_result @items, '#{method}' %>"
end
end
end
end
end
|