I have been trying out text_field_with_auto_complete and initially
defined the following in my view:

<%= text_field_with_auto_complete(:project, :project_code, :size =>
‘10’) %>

with the corresponding code in my controller:

auto_complete_for :project, :project_code

But I wanted the name of the text field to be project_code instead of
project[project_code] so I added a :name option

<%= text_field_with_auto_complete(:project, :project_code, :name =>
‘project_code’, :size => ‘10’) %>

But then this seems to stop the auto_complete working and I cannot
quite see why?

I defined my own method auto_complete_for_project_project_code using
the source from auto_complete_for and then it works but still do not
see what I have really done any different.

def auto_complete_for_project_project_code
method = :project_code
object = :project
options = {}

find_options = {:conditions => [ “LOWER(#{method}) LIKE ?”, ‘%’ +
params[method].downcase + ‘%’ ],
:order => “#{method} ASC”,
:limit => 10 }.merge!(options)
@items = object.to_s.camelize.constantize.find(:all, find_options)
render :inline => “<%= auto_complete_result @items, ‘#{method}’ %>”

I must be doing something stupid :wink: Does anyone have any suggestions?


Shane M.

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