auto_complete_for reimplementation.

Hi!

I would like to create a "custom" version of the "auto_complete_for" function, I took the source code, and altered it to my needs, and, off course, changed the name (from auto_complete_for to custom_auto_complete_for , just for testing purporses). But rails keep complaining that the new method doesn't exits!

I already did something similar with the "error_messages_for" function, and just wrote the new one in the application_helper.rb file, and just worked everywhere... but for the auto_complete_for function: I don't know where to put it, I tried to put it in the helper, in the controller itself, and even in the model: no, it doesn't work, like the function didn't existed.

Any ideas?

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.

_Kevin

Hi!

Thanks for your answer!

> Hi!

> I would like to create a "custom" version of the "auto_complete_for" > function, I took the source code, and altered it to my needs, and, off > course, changed the name (from auto_complete_for to > custom_auto_complete_for , just for testing purporses). But rails keep > complaining that the new method doesn't exits!

> I already did something similar with the "error_messages_for" function, > and just wrote the new one in the application_helper.rb file, and just > worked everywhere... but for the auto_complete_for function: I don't > know where to put it, I tried to put it in the helper, in the > controller itself, and even in the model: no, it doesn't work, like the > function didn't existed.

> Any ideas?

> 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

Hi, again.

I just found this:

http://www.sciwerks.com/blog/2006/09/25/multiple_auto_complete_plugin/

but I can't download the plug-in :frowning: . Does anybody has it?, the server just says:

script/plugin install svn://sciwerks.com/home/sciwerks/public_svn/plugins/multiple_auto_complete svn: Can't connect to host 'sciwerks.com': Connection refused

I would appreciate any help on this..... the plug-in clearly reimplements the auto_complete_for method, wich is exactly what I need to do.

Thanks in advance,

Ildefonso Camargo

I'll check on it.

_Kevin

Should be working now. If you still have trouble email me and I'll send you a copy.

_Kevin