Text_field_with_auto_complete problem

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 %>

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
end

def auto_complete_for_institution_names
search = params[:institution][:names]
breakpoint
@institutions = Institution.search(search) unless search.blank?
render :partial => “live/search”
end

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

    <% for institution in @institutions.to_a -%>
  • <%= institution_link institution.name, institution %>
  • <% end -%>

Hi

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

Darren

i just did this too. (Rails version 1.1.6)
i used the advance version
http://demo.script.aculo.us/ajax/autocompleter_customized (basic
http://demo.script.aculo.us/ajax/autocompleter)
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

view

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

<%= submit_tag 'add' %>

<%= end_form_tag %>

controller

def associate_to_a_project
@item = Item.find(params[:id])
@item.project =
Project.find_or_create_by_name(params[:item][“project_id”])
if @item.update_attributes(params[:item])
flash[:notice] = ‘Project was successfully associated to item.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

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

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


view _projects

    <% for project in @projects do -%>
  • <%=h project.name %>
  • <% 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

hth
John