# Auto\_complete\_for reimplementation

**URL:** <https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890>\
**Category:** Rails\
**Created:** [October 12, 2006, 4:28am UTC](https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890 "2006-10-12T04:28:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![soulhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@soulhunter](https://www.ruby-forum.com/u/soulhunter)\
**Post date:** [October 12, 2006, 4:28am UTC](https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890/1 "2006-10-12T04:28:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![soulhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@soulhunter](https://www.ruby-forum.com/u/soulhunter)\
**Post date:** [October 12, 2006, 5:14am UTC](https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890/2 "2006-10-12T05:14:31Z")

</div>

On Oct 11, 10:24 pm, “soulhunter” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![soulhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@soulhunter](https://www.ruby-forum.com/u/soulhunter)\
**Post date:** [October 12, 2006, 2:02pm UTC](https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890/3 "2006-10-12T14:02:32Z")

</div>

Hi!

Thanks for your answer!

On Oct 11, 11:09 pm, “\_Kevin” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![soulhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@soulhunter](https://www.ruby-forum.com/u/soulhunter)\
**Post date:** [October 14, 2006, 2:56am UTC](https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890/4 "2006-10-14T02:56:50Z")

</div>

I’ll check on it.

\_Kevin

---

<div class="post-metadata">

**Author:** ![soulhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@soulhunter](https://www.ruby-forum.com/u/soulhunter)\
**Post date:** [October 13, 2006, 9:20pm UTC](https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890/5 "2006-10-13T21:20:43Z")

</div>

Hi, again.

I just found this:

[http://www.sciwerks.com/blog/2006/09/25/multiple\_auto\_complete\_plugin/](http://www.sciwerks.com/blog/2006/09/25/multiple_auto_complete_plugin/)

but I can’t download the plug-in ☹ . 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](http://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

---

<div class="post-metadata">

**Author:** ![soulhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@soulhunter](https://www.ruby-forum.com/u/soulhunter)\
**Post date:** [October 14, 2006, 4:45am UTC](https://www.ruby-forum.com/t/auto-complete-for-reimplementation/71890/6 "2006-10-14T04:45:06Z")

</div>

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

\_Kevin
