# Autocomplete does nothing

**URL:** <https://www.ruby-forum.com/t/autocomplete-does-nothing/138012>\
**Category:** Rails\
**Created:** [May 19, 2008, 2:00pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012 "2008-05-19T14:00:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 2:00pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/1 "2008-05-19T14:00:00Z")

</div>

hi…

I use auto\_complete…

put this in my controllerBestemming:

auto\_complete\_for :bestemming, :naam

This works fine…

But when i make a action in controllerBestemming, below…it does  
nothing…

def auto\_complete\_for\_bestemming\_naam  
@bestemmingen = Bestemming.find(:all,  
:conditions =\> [ ‘LOWER(naam) LIKE ?’,  
‘%’ + request.raw\_post.downcase + ‘%’ ])  
render :inline =\> “\<%= auto\_complete\_result(@bestemmingen, ‘naam’)  
%\>”  
end

What i am doing wrong?

grtz…remco

---

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 2:03pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/2 "2008-05-19T14:03:03Z")

</div>

Perhaps due to the protect\_from\_forgery line in your application.rb  
file.  
Try commenting this out and see if it works, if you don’t care about  
people  
forging your forms 🙂

On Mon, May 19, 2008 at 9:30 PM, Remco Z. \<  
removed\_email\_address@domain.invalid\> wrote:

> end
> 
> What i am doing wrong?
> 
> ## grtz…remco
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Appreciated my help?  
Reccommend me on Working With Rails  
[http://workingwithrails.com/person/11030-ryan-bigg](http://workingwithrails.com/person/11030-ryan-bigg)

---

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/3 "2008-05-19T15:02:44Z")

</div>

Ryan B. wrote:

> Perhaps due to the protect\_from\_forgery line in your application.rb  
> file.  
> Try commenting this out and see if it works, if you don’t care about  
> people  
> forging your forms 🙂
> 
> On Mon, May 19, 2008 at 9:30 PM, Remco Z. \<  
> removed\_email\_address@domain.invalid\> wrote:
> 
> > end
> > 
> > What i am doing wrong?
> > 
> > ## grtz…remco
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> Appreciated my help?  
> Reccommend me on Working With Rails  
> [http://workingwithrails.com/person/11030-ryan-bigg](http://workingwithrails.com/person/11030-ryan-bigg)

Hi…this works…

def auto\_complete\_for\_bestemming\_naam  
bestemming\_search = params[:bestemming][:naam]  
@bestemmingen = Bestemming.find(:all,  
:conditions =\> [ ‘LOWER(naam) LIKE ?’,  
bestemming\_search.downcase + ‘%’ ],  
:order =\> ‘naam ASC’)  
render :partial =\> ‘autocomplete’  
end

\_autocomplete.rhtml

\<%= auto\_complete\_result(@bestemmingen, ‘naam’) %\>

Bu when i change \_autocomplete.rhtml to

\<% for bestemming in @bestemmingen -%\>  
\<%= bestemmingen.naam %\>  
\<% end -%\>

I doesn’t work…anymore…

Must i use the helper “auto\_complete\_result” or is my partial-code not  
good?

remco

---

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/4 "2008-05-19T15:29:03Z")

</div>

Peter De Berdt wrote:

> On 19 May 2008, at 15:02, Remco Z. wrote:
> 
> > \<%= auto\_complete\_result(@bestemmingen, ‘naam’) %\>
> > 
> > Bu when i change \_autocomplete.rhtml to
> > 
> > \<% for bestemming in @bestemmingen -%\>  
> > \<%= bestemmingen.naam %\>  
> > \<% end -%\>
> 
> Well, you’re using a non-existent local variable “bestemmingen”  
> instead of “bestemming” as you named it in the first line.
> 
> > I doesn’t work…anymore…
> > 
> > Must i use the helper “auto\_complete\_result” or is my partial-code not  
> > good?
> 
> Also remember that Rails as a framework uses English as its main  
> language, you’ll run into problems sooner or later because the  
> singular/plural inflectors can never do their job well. Even if you  
> would like to make your urls make sense to a Dutch-speaking person,  
> you could still use English controller names, English named models and  
> fields and just adjust your routes file to hide the default English  
> name and replace it with the Dutch version.
> 
> Best regards
> 
> Peter De Berdt

hi Peter…

Do you have some url’s with some documentation how i can realize  
dutch-language urls with english models/controllers…

remco

---

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 3:42pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/5 "2008-05-19T15:42:56Z")

</div>

On 19 May 2008, at 15:29, Remco Z. wrote:

> Do you have some url’s with some documentation how i can realize  
> dutch-language urls with english models/controllers…

Your models shouldn’t be a problem at all, since the MVC model implies  
that your user will never see model names throughout the application.  
If you want your field names to be translated, you can use  
simple\_localization ([http://simple-localization.arkanis.de/](http://simple-localization.arkanis.de/)), which I  
prefer over Globalize. It will allow you to map the fieldnames to the  
translation.

Using your “bestemmingen” example, something like this should work:  
map.resources :destinations, :as =\> ‘bestemmingen’, :singular =\>  
‘bestemming’

That is assuming that you use the RESTful conventions.

All of this should be right there in the Rails API somewhere.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 10:05pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/6 "2008-05-19T22:05:52Z")

</div>

Peter De Berdt wrote:

> On 19 May 2008, at 15:29, Remco Z. wrote:
> 
> > Do you have some url’s with some documentation how i can realize  
> > dutch-language urls with english models/controllers…
> 
> Your models shouldn’t be a problem at all, since the MVC model implies  
> that your user will never see model names throughout the application.  
> If you want your field names to be translated, you can use  
> simple\_localization ([http://simple-localization.arkanis.de/](http://simple-localization.arkanis.de/)), which I  
> prefer over Globalize. It will allow you to map the fieldnames to the  
> translation.
> 
> Using your “bestemmingen” example, something like this should work:  
> map.resources :destinations, :as =\> ‘bestemmingen’, :singular =\>  
> ‘bestemming’
> 
> That is assuming that you use the RESTful conventions.
> 
> All of this should be right there in the Rails API somewhere.
> 
> Best regards
> 
> Peter De Berdt

hi Peter…

Thanks for you’re reply. i am going to check the url…

Groet, remco

---

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 11:21pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/7 "2008-05-19T23:21:03Z")

</div>

If you want to keep your Dutch model names, you can define your  
pluralization rules globally in /config/initializers/inflections.rb  
(Rails  
1: config/environment.rb), like this:

Inflector.inflections do |inflect|  
inflect.plural /([aeou])+([^aeiouy])$/i, ‘\1\2en’  
inflect.singular /([aeou])([^aeiouy])en$/i, ‘\1\1\2’  
inflect.plural /([^aeiouy])$/i, ‘\1en’  
inflect.singular /([^aeiouy])en$/i, ‘\1’  
end

or if you’re not good at regexen, just do it per model name:

Inflector.inflections do |inflect|  
inflect.irregular ‘land’, ‘landen’  
…

and you can check them in irb with:

‘naam’.pluralize #=\> ‘namen’  
‘namen’.singularize #=\> ‘naam’  
‘land’.pluralize #=\> ‘landen’  
‘landen’.singularize #=\> ‘land’

For anything that doesn’t match your custom rules, the default English  
rules are used.

But it’s tricky. I’ve tried it for German, kept running into errors and  
ended up refactoring to English table names. Dutch plurals are simpler,  
so  
it could work for you.

---

<div class="post-metadata">

**Author:** ![remco123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@remco123](https://www.ruby-forum.com/u/remco123)\
**Post date:** [May 19, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/autocomplete-does-nothing/138012/8 "2008-05-19T15:21:40Z")

</div>

On 19 May 2008, at 15:02, Remco Z. wrote:

> \<%= auto\_complete\_result(@bestemmingen, ‘naam’) %\>
> 
> Bu when i change \_autocomplete.rhtml to
> 
> \<% for bestemming in @bestemmingen -%\>  
> \<%= bestemmingen.naam %\>  
> \<% end -%\>

Well, you’re using a non-existent local variable “bestemmingen”  
instead of “bestemming” as you named it in the first line.

> I doesn’t work…anymore…
> 
> Must i use the helper “auto\_complete\_result” or is my partial-code not  
> good?

Also remember that Rails as a framework uses English as its main  
language, you’ll run into problems sooner or later because the  
singular/plural inflectors can never do their job well. Even if you  
would like to make your urls make sense to a Dutch-speaking person,  
you could still use English controller names, English named models and  
fields and just adjust your routes file to hide the default English  
name and replace it with the Dutch version.

Best regards

Peter De Berdt
