From 8a145b251afb2e043669cb2bf74826070f98f66d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 29 Jun 2005 17:08:14 +0000 Subject: Give auto_complete_for parameters, fix browser-autocompletion #1550 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1566 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/auto_complete.rb | 11 ++++++----- actionpack/lib/action_view/helpers/javascript_helper.rb | 6 +++++- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/auto_complete.rb b/actionpack/lib/action_controller/auto_complete.rb index 606f43b350..c2590c66b4 100644 --- a/actionpack/lib/action_controller/auto_complete.rb +++ b/actionpack/lib/action_controller/auto_complete.rb @@ -15,13 +15,14 @@ module ActionController end module ClassMethods - def auto_complete_for(object, method) + def auto_complete_for(object, method, options = {}) define_method("auto_complete_for_#{object}_#{method}") do - @items = object.to_s.camelize.constantize.find( - :all, + find_options = { :conditions => [ "LOWER(#{method}) LIKE ?", '%' + request.raw_post.downcase + '%' ], - :order => "#{method} ASC" - ) + :order => "#{method} ASC", + :limit => 10 }.merge!(options) + + @items = object.to_s.camelize.constantize.find(:all, find_options) render :inline => "<%= auto_complete_result @items, '#{method}' %>" end diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index c73c1e08b0..607b8fe0f9 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -259,6 +259,10 @@ module ActionView # # This function expects that the called action returns a HTML