# Text\_field\_with\_auto\_complete in a component?

**URL:** <https://www.ruby-forum.com/t/text-field-with-auto-complete-in-a-component/138215>\
**Category:** Rails\
**Created:** [May 21, 2008, 4:42am UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-in-a-component/138215 "2008-05-21T04:42:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [May 21, 2008, 4:42am UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-in-a-component/138215/1 "2008-05-21T04:42:34Z")

</div>

Maybe this one is just way too esoteric to matter all that much, but  
it’s bugging me. I’m doing a prototype for demonstration on Thursday,  
and making heavy use of components (scalability/performance not a  
concern, but rapid development of small contained pieces is). Here’s  
my problem - it looks like a text\_field\_with\_auto\_complete doesn’t work  
in a component, because of the changing controller.

I’ve got main/index.rhtml, from which I render component/index.rhtml.

In component/index.rhtml I have a text\_field\_with\_auto\_complete :person,  
:name

When it runs, however, I get an error because Rails looks for the  
auto\_complete\_for\_person\_name method on the _main_ controller, rather  
than the _component_ controller. I mean, I can see why it does that,  
I’m just trying to figure out a way around it. Best I can tell there’s  
no :controller=\>“component” option I can slap on the text field.

The strange thing is that if I do an Ajax update on the  
component/index.rhtml page (sort of “portlet” style where just the div  
updates), then the text\_field\_with\_auto\_complete works fine. So  
something about the Ajax update changes the context under which the text  
field is rendering, so that it knows it is now in the component/  
controller instead of main/.

Anybody got any suggestions?

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [May 21, 2008, 12:14pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-in-a-component/138215/2 "2008-05-21T12:14:54Z")

</div>

On Wed, May 21, 2008 at 4:42 AM, Duane M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Maybe this one is just way too esoteric to matter all that much, but  
> it’s bugging me. I’m doing a prototype for demonstration on Thursday,  
> and making heavy use of components (scalability/performance not a  
> concern, but rapid development of small contained pieces is). Here’s  
> my problem - it looks like a text\_field\_with\_auto\_complete doesn’t work  
> in a component, because of the changing controller.

Pass :url in the rightmost options parameter:

def text\_field\_with\_auto\_complete(object, method, tag\_options = {},  
completion\_options = {})

like this:

\<%= text\_field\_with\_auto\_complete :user, :name, {}, :url =\> { … }  
%\>

That’s a regular :url option, you may assign a named route as well for  
example.

– fxn
