Rails Auto Completion plugin using jQuery-UI1 widget; it works similarly to the original rails auto complete, but generating unobtrusive javascript. Additional features:
- named scope items filtering, based on a customized list of autocomplete options.
WARNING NOTE: This is an active work in progress – currently only used on few live projects right now. Use at your own discretion.
In the controller you can use the macro function as such
class ExampleController < ApplicationController
auto_complete_for :fruit, :name
...
end
In your views:
<%= text_field_with_auto_complete :fruit, :name %>
be sure to include the jquery/jquery-ui javascript in your layout:
<%= javascript_include_tag 'jquery, 'jquery-ui.min', 'jquery-ui-i18n.min' %>
auto_complete_for now optionally accepts a block that is called with the item list and HTTP parameters when the auto complete AJAX request is received. This block can be used to specify that a named scope be used to generate a customized list of autocomplete options.
auto_complete_for :fruit, :shape do |items, params|
items.scoped( { :conditions => [ "colour = ?", params['fruit']['color'] ] })
end
Having the model:
class Fruit < ActiveRecord::Base
belongs_to :owner
named_scope :by_owner,
lambda { |owner_name| {
:include => :owner,
:conditions => [ "owner.name = ?", owner_name ]
} }
end
In the controller you can use the macro function as such
auto_complete_for :fruit, :name do | items, params |
items.by_owner(params['owner'])
end
- test, test… test!
Please direct all queries to the issue tracker: https://github.com/michelefranzin/jquery_autocomplete/issues
Thanks to Paul Smith for the original idea and Pat Shaughnessy for inspirating me the named scope part.
Copyright © 2010 Michele Franzin. See LICENSE for details.