mirror of
https://github.com/github/rails.git
synced 2026-02-10 22:25:02 -05:00
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1526 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
31 lines
830 B
Ruby
31 lines
830 B
Ruby
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 |