Search code examples
ruby-on-railsjquery-ui-autocompletesearch-form

How do I create an autocomplete search form in rails 3 using rails3-jquery-autocomplete?


I am using this gem:

https://github.com/crowdint/rails3-jquery-autocomplete

I am having difficulty making the auto-complete work and also to create a simple search. This is what I have in the view:

 16     - semantic_form_for vendors_path do |f| 
 17       - f.autocompleted_input :name, :url => autocomplete_vendor_name_home_index_path 

The url isn't making sense to me.

Here is the output HTML:

<input data-autocomplete="/home/autocomplete_vendor_name" id="_vendors_name" name="/vendors[name]" required="required" size="30" type="text" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">

And I don't want to create a new vendor, I want to submit a search...but first am trying to get the autocomplete to work.

Suggestions?


Solution

  • An example from one of my projects:

    routes.rb: get 'users/autocomplete_category_name'
    

    view:

    <%= form_tag 'users/index' do %>
      <%= autocomplete_field_tag 'name', '', users_autocomplete_category_name_path, :size => 75 %>
    <% end %>