I have a field where a user enters his city. I want to add
autocompletion to this field based on a table with a predefined set of
cities not based on previous entries of other users. How can I do this?
I know about the method described in rails recipes which allows to
cache a predefined set of values for autocompletion
(Autocomplete.Local). This is not what I’m looking for though because
my list of cities is very long and I don’t want to cache it.
I have a field where a user enters his city. I want to add
autocompletion to this field based on a table with a predefined set of
cities not based on previous entries of other users. How can I do this?
I know about the method described in rails recipes which allows to
cache a predefined set of values for autocompletion
(Autocomplete.Local). This is not what I’m looking for though because
my list of cities is very long and I don’t want to cache it.
You can write your own “auto_complete_for_#{object}_#{method}” method
pretty easily, rather than calling auto_complete_for to generate it
for you. The source code of auto_complete_for is a good starting
point.
the part causing problems is params[city][name]. Is this really the
variable which stores the letters typed into the field ad[city]? The
error message is: undefined local variable or method `ad’ for
#AdsController:0xb79908c0
the part causing problems is params[city][name]. Is this really the
variable which stores the letters typed into the field ad[city]? The
error message is: undefined local variable or method `ad’ for
#AdsController:0xb79908c0
41: :order => “#{method} ASC”,
However, the following adaption dowsn’t work (in the controller):
end
params[:ad][:city]
If that’s not where your trouble lies, look at your development log
file. Every param is logged there, so you should be able to see the
names being used.
the part causing problems is params[city][name]. Is this really the
variable which stores the letters typed into the field ad[city]? The
error message is: undefined local variable or method `ad’ for
#AdsController:0xb79908c0
Any ideas?
Did you really mean this instead?
params[:ad][:city]
If that’s not where your trouble lies, look at your development log
file. Every param is logged there, so you should be able to see the
names being used.
– James
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.