Autocomplete does nothing

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

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 :slight_smile:

On Mon, May 19, 2008 at 9:30 PM, Remco Z. <
[email protected]> wrote:

end

What i am doing wrong?

grtz…remco

Posted via http://www.ruby-forum.com/.


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

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 :slight_smile:

On Mon, May 19, 2008 at 9:30 PM, Remco Z. <
[email protected]> wrote:

end

What i am doing wrong?

grtz…remco

Posted via http://www.ruby-forum.com/.


Appreciated my help?
Reccommend me on Working With Rails
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

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

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/), 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

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/), 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

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs