Forum: Ruby on Rails text_field_with_auto_complete problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D5ca9a8e0973ac2a1871a53c6e67b0d8?d=identicon&s=25 Darren Evans (darrenevans2)
on 2007-01-25 06:06
I have some difficulties with text_field_with_auto_complete. I’m new to
this, it just will not work, I must be doing something wrong. It would
be great if someone could advise me. I have tried to follow advice
available on the internet, so I don’t know what the problem is. The
script gets as far as the breakpoint in the controller, but it doesn’t
like the next line – giving the error message “undefined method or local
variable search”. This is what I have…

I have downloaded the .js files from aculo and followed their
instructions. I have put the .js files in a folder called “Javascripts”
in the root of my application.

My table is called institutions and the field is called name

I have added the following to the head of my layout:

<%= javascript_include_tag :defaults %>
<script src="javascripts/prototype.js" type="text/javascript"></script>
<script src="javascripts/scriptaculous.js"

My view is called place and is the following:

        <%= text_field_with_auto_complete :institution, :names, { :size
=> 15 }, :skip_style => true -%>

In the controller I have:

def place

def auto_complete_for_institution_names
  search = params[:institution][:names]
  @institutions = unless search.blank?
  render :partial => "live/search"

Then I have a partial called “_live.rhtml”, which contains:

<ul class="autocomplete_list">
  <% for institution in @institutions.to_a -%>
    <li class="autocomplete_item"><%= institution_link,
institution %></li>
  <% end -%>
Cd50d7d342c0d0bfef5c7e319ec1549b?d=identicon&s=25 Darren Evans (Guest)
on 2007-01-25 16:22

I still haven't managed to resolve this issue, is this in some way
related to the rails helpers or something???

316c03a99e8ed311e5462d94f085fc2e?d=identicon&s=25 John Ivanoff (Guest)
on 2007-01-25 18:11
(Received via mailing list)
i just did this too. (Rails version  1.1.6)
i used the advance version (basic
i have an item that i want to associate to a project.

in the head of my layout I only call
  <%= javascript_include_tag :defaults %>
I did not create a javascript folder

<%= start_form_tag :action => 'associate_to_a_project', :id => @item %>
    <%= text_field_with_auto_complete :item, :project_id, {} %>

    <%= submit_tag 'add' %>

<%= end_form_tag %>


  def associate_to_a_project
    @item = Item.find(params[:id])
    @item.project =
    if @item.update_attributes(params[:item])
      flash[:notice] = 'Project was successfully associated to item.'
      redirect_to :action => 'list'
      render :action => 'new'

  def auto_complete_for_item_project_id
    auto_complete_responder_for_projects params[:item][:project_id]

  def auto_complete_responder_for_projects(value)
    @projects = Project.find(:all,
      :conditions => [ 'LOWER(name) LIKE ?',
      '%' + value.downcase + '%' ],
      :order => 'name ASC')
    render :partial => 'projects'


view _projects
<ul class="projects">
<% for project in @projects do -%>
  <li><%=h %></li>
<% end -%>

and it worked. It did take me sometime to get scriptolicious'
instructions to work for my app but it was just figuring out what
variable to change/pass

This topic is locked and can not be replied to.