Guest User

Untitled

a guest
May 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. module AutoComplete
  2.  
  3. def self.included(base)
  4. base.extend(ClassMethods)
  5. end
  6.  
  7. module ClassMethods
  8. def auto_complete_for(object, method, options = {})
  9. define_method("auto_complete_for_#{object}_#{method}") do
  10. find_options = {
  11. :conditions => [ "LOWER(#{method}) LIKE ?", '%' + params[object][method].downcase + '%' ],
  12. :order => "#{method} ASC",
  13. :limit => 10 }.merge!(options)
  14.  
  15. @items = object.to_s.camelize.constantize.find(:all, find_options)
  16.  
  17. render :inline => "<%= auto_complete_result @items, '#{method}' %>"
  18. end
  19. end
  20. end
  21.  
  22. end
Add Comment
Please, Sign In to add comment