You can also write your own logic for this, since I don't think the plugin is going to introduce itself:
I assume that there are identifiers in the city and country. If not, the logic will be simpler. Use jQueryUI autocomplete to run autocomplete for your element. Add a controller method that will give the label of your city and country (probably the method for the city object) along with your ids back as json. In the "select" completion callback, set hidden fields in the form for city and country identifiers. This last part is optional because I donβt know how you plan to save this data from the form.
The following examples assume a LOT about your application, but should be enough to get you started:
example script for view:
$("#yourField").autocomplete({ source: "/path_to_your_action", minLength: 2, select: function( event, ui ) { $(this).val(ui.item.label); $(this).find("#country_id").val(ui.item.country_id); $(this).find("#city_id").val(ui.item.city_id); event.preventDefault; } })
controller:
def your_action term = params[:term] cities = City.where("cities.name like ?", "%#{term}%") .limit(25) .all render :json=>cities.collect{|c| {:label=>c.your_label_method, :city_id=>c.id, :country_id=>c.country_id}} end
city.rb
def your_label_method "#{self.name}, #{self.country.name)}" end
miked source share