diff options
Diffstat (limited to 'actionpack/lib/action_controller/auto_complete.rb')
-rw-r--r-- | actionpack/lib/action_controller/auto_complete.rb | 11 |
1 files changed, 6 insertions, 5 deletions
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 |