2

I'm having difficulty setting up JQuery Autocomplete with Rails3. I don't get any errors, it just behaves like regular text box.

Here is what I have done:

First I installed autocomplete as explained here: http://github.com/crowdint/rails3-jquery-autocomplete#readme

I have a model class which contains the model which will be in the lookup:

class NdbFoodDesController < ApplicationController
  autocomplete :ndb_no, :long_desc

  ... some other functions
end

Then I added the function in the routes file:

resources :ndb_food_des do
    get :autocomplete_ndb_no_long_desc, :on => :collection
  end

Then in the view form I have added these lines:

<% f.fields_for :ingredients_recipes do |rif| %>
  <% javascript_include_tag "autocomplete-rails.js" %>  
  <td>
    <input type="text" autocomplete="/ndb_food_des/autocomplete_ndb_no_long_desc" id_element="#ndb_no">
  </td>
  <td>
    <%= rif.autocomplete_field :long_desc, autocomplete_ndb_no_long_desc_ndb_food_des_path %>
  </td>
<% end %>

Is there something I'm doing wrong?

2
  • Is there nobody who has knowledge of how this can be achived? Commented Oct 13, 2010 at 22:03
  • I'm having the same problem gugguson, did you ever resolve this? Commented Feb 1, 2011 at 3:46

2 Answers 2

1
  1. Javascript include tags must be loaded in the html hader (in your layout file)
  2. autocomplete_tag doesnt work, use text_field instead

Don't forget that you also need jquery installed since they are not included in rails, see http://asciicasts.com/episodes/205-unobtrusive-javascript for reference and an alternative search method.

If it still doesn't work check the output of the server-console, usually it tells you what doesn't fit.

Sign up to request clarification or add additional context in comments.

Comments

0

A warning to new readers on this.. rails3-jquery-autocomplete (1.0.10) only supports autocomplete_field_tag. Older versions (0.6.0 was the default used in the rails3-jquery-autocomplete-app) support both. Be sure to check the version of the gem you are using.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.