Hi!
Thanks for your answer!
On Oct 11, 11:09 pm, “_Kevin” [email protected] wrote:
complaining that the new method doesn’t exits!
Ildefonso Camargo
If you want to override the standard ‘auto_complete_for :action,
:method’, all you have to do is define a method named
‘auto_complete_for_action_method’ in your controller and skip the
‘auto_complete_for’ line completely.
Yes, I know, I already did that, but the thing is: I want to replace
ALL the autocompletions in my project (more than 20), because I want to
change the search conditions (from LIKE to ~* , and need to add some
character substitution).
Thus, I tried to define this method (for testing purporses):
def custom_auto_complete_for(object, method, options = {})
define_method("auto_complete_for_#{object}_#{method}") do
find_options = {
:conditions => [ "#{method} ~* ? ", '%' +
params[object][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}' %>"
end
end
That is my first approach, but when I try to call it, rails would just
say:
undefined method `custom_auto_complete_for’ for
ContribuyentesController:Class
and the log says:
NoMethodError (undefined method `custom_auto_complete_for’ for
ContribuyentesController:Class):
I defined the method in application_helper.rb , but I also tried to
define it locally in the “contribuyentes_controller.rb” file: I get the
same error.
Thanks in advance,
Ildefonso Camargo