This is the jQuery-UI autocompleter. All options and events provided by the jQuery autocompleter are supported in this Hobo tag. Refer to the jquery autocomplete documentation for more details.

If you do not provide a source option, this tag will essentially provide a default similar to this:

<autocomplete:project source="&Project.find(:all, :limit => 5000).map {|p| p.name}" />

This will provide a local autocomplete, putting all possible options into your HTML. This is useful when you have too many options to make a select-one infeasible, but will overload your server and crash your browser if you have millions of options.

To do server side autocomplete, you need a controller action like:

class FoosController < ActionController:Base
  autocomplete :bar

<autocomplete:foo source="&complete_bar_foos_path" />

The argument to the controller’s autocomplete is optional. If not supplied the name attribute for the model should be used in the source attribute.

If you do not wish to use the Hobo autocomplete or hobo_completions functions in your controller, it is very easy to roll your own. For example:

<autocomplete:project source="&query_projects_path" delay="500" minLength="3" />

Could be served by:

index_action :query do
  render :json => Project.name_contains(params[:term]).limit(100).*.name

Show Source

Edit this page