Sha256: 3cec9924a3097f7dcae0b529f020fe2143004454938dba9927ca4d64dde8565a
Contents?: true
Size: 1.22 KB
Versions: 4
Compression:
Stored size: 1.22 KB
Contents
class AdminAssistant module Request class Autocomplete < Base def associated_class @associated_class ||= Module.const_get( underscored_assoc_class_name.camelize ) end def call render_template_file( 'autocomplete', :layout => false, :locals => { :records => records, :prefix => underscored_assoc_class_name, :associated_class => associated_class } ) end def records action =~ /autocomplete_(.*)/ associated_class = Module.const_get $1.camelize target = AssociationTarget.new associated_class field = target.default_name_method associated_class.find( :all, :conditions => [ "LOWER(#{field}) like ?", "%#{search_string.downcase unless search_string.nil?}%" ], :limit => 10, :order => "length(#{field}), lower(#{field})" ) end def search_string @controller.params[ "#{underscored_assoc_class_name}_autocomplete_input" ] end def underscored_assoc_class_name action =~ /autocomplete_(.*)/ $1 end end end end
Version data entries
4 entries across 4 versions & 1 rubygems