This is not a plugin, but with a little jQuery magic you can use http://github.com/chadisfaction/jQuery-Tokenizing-Autocomplete-Plugin . The best part about this is that since it is pure JS in its implementation, you can create an AJAX call yourself in Rails and display only what you want. It even allows you to add a stylesheet to the drop-down list if you want to make it more like Facebook. In the controller, add a function so that the AJAX call returns the list of strings in JSON:
def taglist tags = [] sql = "SELECT id,name ... LIMIT 15" # Enter SQL here to produce a possible result set result = ActiveRecord::Base.connection.execute(sql) # Iterate over the hash values and push them into an array result.each { |field| tags.push( {"id" => field[0], "name" => field[1]} ) } result.free render :json => tags, :layout => false end
In the view, add the following code:
<%= javascript_include_tag 'jquery.tokeninput' %> <%= stylesheet_link_tag 'token-input-facebook' %> <script type="text/javascript"> jQuery(document).ready(function () { jQuery("#actors_role").tokenInput("/actors/rolesearch", { allowNewValues: false, canCreate: false, hintText: "Enter the actor name or role they played", }); }); </script>
source share