# Auto complete

**URL:** <https://www.ruby-forum.com/t/auto-complete/191436>\
**Category:** Rails\
**Created:** [July 12, 2010, 5:52pm UTC](https://www.ruby-forum.com/t/auto-complete/191436 "2010-07-12T17:52:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [July 12, 2010, 5:52pm UTC](https://www.ruby-forum.com/t/auto-complete/191436/1 "2010-07-12T17:52:00Z")

</div>

I saw an example of the auto complete field sending a ajax request in  
this format that allows a method in the controller to catch all auto  
complete ajax requests:

‘/rails/app/auto\_complete\_for/sample\_origin’

but when I use it, the request is

‘/rails/app/auto\_complete\_for\_sample\_origin’

My template says this

\<%=text\_field\_with\_auto\_complete :sample, c, {:skip\_style=\>true}%\>

How can I change it so that the request is ‘/rails/app/  
auto\_complete\_for/sample\_origin’ ?

---

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [July 13, 2010, 10:14am UTC](https://www.ruby-forum.com/t/auto-complete/191436/2 "2010-07-13T10:14:53Z")

</div>

I changed the url in the macros helper file:

:url =\> { :action =\> “auto\_complete\_for”, :id=\>"#{object}\_#{method}" }

def text\_field\_with\_auto\_complete(object, method, tag\_options = {},  
completion\_options = {})  
(completion\_options[:skip\_style] ? “” : auto\_complete\_stylesheet)  
+  
text\_field(object, method, tag\_options) +  
content\_tag(“div”, “”, :id =\> “#{object}\_#{method}  
_auto\_complete", :class =\> “auto\_complete”) +  
auto\_complete\_field("#{object}_#{method}”, { :url =\> { :action =\>  
“auto\_complete\_for”, :id=\>"#{object}  
\_#{method}" } }.update(completion\_options))  
end

Now I can write a method that applies to all auto complete fields.
