model_auto_completer
I think a company that takes as much from open source as mine has to contribute back somehow. In this line, this week we extracted, polished, and published as Rails plugin a widget we wrote for a project. That's model_auto_completer.
In Rails there's a builtin textfield with autocompletion (via Ajax, you know). With that textfield you are able to offer autocompletion of strings. But sometimes you'd like to be able to autocomplete something to select a model.
Say you are implementing a bookstore backoffice. In the form for book edition you want the user to be able to assign an author to the book, but there are hundreds of authors in the database, so a select is not usable. With this plugin you can offer a textfield that autocompletes by author name and manages a hidden field with the corresponding database ID under the hood.
In its most basic use case the usage is:
<%= belongs_to_auto_completer :book, :author, :fullname %>
Things are defined in such a way that you don't need to do anything special in the action that processes the form, update_attributes(params[:book]) will work out of the box.
There are some options available, a much more generic helper, and the ubiquitous class method for controllers that generates an action dynamically.
We wrote the widget on top of the builtin autocompletion facilities provided by Rails, so the contract with the action is the same, except list items are expected to have an ID attribute. By default, any trailing integer there is assumed to be the ID of the corresponding model. That's a configurable regexp and it is a weak contract on purpose, so users can easily avoid HTML ID collisions.
The generated HTML elements have a trailing random suffix as well in their IDs, so that you can include more than one widget for the same completion in the same page.