Plugin auto_complete - unable to get it to work at all

I’m having a little trouble trying to understand how autocomplete works.
This is namely because there are so many plugins out there and some are
outdated and many come with mixed instructions.

I’m using the standard plugin called auto_complete from David Heinemeier

Here’s what I have so far:

Teams controller

auto_complete_for :team, :name

def virtual_matchups
@teams = Team.find(:all, :conditions => [‘name LIKE ?’,

Created a custom method called virtual_matchups. The name of the model
is Team and the name of the team name field is name.

I created a custom view:


Test Virtual Matchups

<%= text_field_with_auto_complete :team, :name %>

I added the following to routes.rb:

map.auto_complete ‘:controller/:action’, :requirements => { :action =>
/auto_complete_for_\S+/ }, :conditions => { :method => :get }

I go to http://localhost:3000/teams/virtual_matchups

… I get:

Couldn’t find Team with ID=virtual_matchups

I go to http://localhost:3000/teams/virtual_matchups/1

… I get:

the text field box but when typing into it, it does nothing…

I could use some help with a step by step procedure on how to use auto
complete. If I can do it just one time, I’m sure I could figure it out.
However, I’ve been messing around with the regular version, a jquery
version, even the ryan bates railscast and “none of them” work…

However, all start right in the middle of something and never explain
how to use it step by step from the beginning. I can’t find a solid
tutorial on using the plugin.


Posted via

I believe I found a partial answer:

In my teams controller I placed:

class TeamsController < ApplicationController
skip_before_filter :verify_authenticity_token, :only =>

def auto_complete_for_team_name()
team_name = params[:team][:name]
@teams = Team.find(:all, :conditions => [‘name LIKE ?’, “%” +
team_name + “%”])
render :partial => ‘teamname’

def virtual_matchups

In my virtual_matchups.html.erb file I placed as a test:

Test Virtual Matchups

<%= text_field_with_auto_complete :team, :name ,{}, :skip_style => false %>

I created a partial for teamname:

    <% for team in @teams do %>
  • <%=h %>
  • <% end %>

In my routing file I placed:

map.virtual_matchups ‘/virtual_matchups’, :controller => ‘teams’,
:action => ‘virtual_matchups’

I restarted the server and the autocomplete works for this page, but I
haven’t tried it with a form.

My thoughts on this are it was very cumbersome to get it to work. I had
to go through several different sites, put together all the pieces of
the puzzle before it finally worked.

I have no idea why I had to use the skip_before_filter but without it,
it would not autocomplete.

Can someone please look over the fixes I provided and if you have
knowledge of autocomplete let me know if there is a simpler way of
getting it to work, and/or what I need to do to polish up the code I
created thus far to get it to work?

I will need two fields and a submit button that performs a query to the
same controller but to a different action that will render a completely
different partial containing information.

Many thanks in advance.

Posted via

my guess:
auto_complete_for_team_name is called through ajax and the ajax call
does not provide (bring along) any authenticity_token…

On Jul 24, 6:59 am, “Älphä Blüë” [email protected]

Thanks Clemens.

Well I will continue to use the skip_before_filter with the only
statement against that particular method then. This seems the easiest
implementation as my search results finds a lot more problems doing
other things…

links which substantiate my guess :wink:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs