Thomas r. Koll wrote:
Hi,
could you post the relevant code where you change the behaviour of
the find and :order ?
cioa, tom
Hi Tom,
I modified the autocomplete_for function in autocomplete.rb
<code>
# arthur: override the find_order options
find_options = {
:conditions => [ "LOWER(#{method}) LIKE ?",
'%'+params[:q].to_s.downcase + '%' ],
:order => options.delete(:find_order) || "#{method} ASC",
# arthur, allow customization of find order
:limit => options[:limit] || 10
}.merge!(options)
# arthur, customize find methods
find_method = find_options.delete(:find_method)
if options[:find_method]
@items =
object.to_s.camelize.constantize.send(options[:find_method],
params[:q].to_s.downcase, find_options)
else
@items = object.to_s.camelize.constantize.find(:all,
find_options)
end
</code>
Therefore, in my controller,
<code>
#autocomplete_for :city, :city, :limit => 15
autocomplete_for :city, :city, :limit => 10,
:find_method => "autocomplete_for_ccr",
:find_order => "priority DESC, AccentCity, country, region" do
items>
items.map{|item|
"#{item.ccr(:capitalize=>true)}|#{item.cr}|#{item.country}"}.join("\n")
end
</code>
I supposed that the suggestions will be ordered by the priority field in
my cities table, but it is not always true.
On the other hand, I use jQuery autocomplete as the javascript plugins.
Arthur