thiebo
thiebo

Reputation: 1435

json autocomplete wrong url in rails

I'm using jquery autocomplete on several places of my app, including in a form with url :

http://www.fonsiuris.net/fr/administration/actes/nouveau/122

app/views/administration/actes form has this field:

<%= lieux.text_area :place, :value =>  params[:acte] ? @place["place"] : "", class:"field_places", data: {autocomplete_source: lieux_enum_path} %>

in routes.rb:

 get 'lieux/enum' => 'lieux#enum'

This is the very first url of my routes.rb

However, when I type letters in the text area, such as 'Dou' that has the autocomplete function, it points to this url :

http://www.fonsiuris.net/fr/biblios/trouver?utf8=✓&ch_bib[aut_titre_cherche]=Douai&commit.x=6&commit.y=2&term=Dou

and when I type in more than one term, that term gets added to the url like this :

/fr/biblios/trouver?utf8=%E2%9C%93&ch_bib%5Baut_titre_cherche%5D=Douai&commit.x=5&commit.y=11&term=Paris

(both Douai and Paris are added as search terms)

It should point to this url:

http://www.fonsiuris.net/lieux/enum?term=Dou

Which gives the right result. I'm using the same code, with the same javascript in several places of my application and it's working fine on all other places !

The output of rails routes | grep enum is :

                          lieux_enum GET    /lieux/enum(.:format)                                          lieux#enum
                       motclefs_enum GET    /motclefs/enum(.:format)                                       motclefs#enum
                 actes_enum_acte_mot GET    /actes/enum_acte_mot(.:format)                                 actes#enum_acte_mot
                    biblios_enum_rec GET    /biblios/enum_rec(.:format)                                    biblios#enum_rec
        administration_archives_enum GET    /administration/archives/enum(.:format)                        administration/archives#enum_archive
         administration_biblios_enum GET    (/:locale)/administration/biblios/enum(.:format)               administration/biblios#enum_titres {:locale=>/fr|en|nl|it/}
         administration_auteurs_enum GET    (/:locale)/administration/auteurs/enum(.:format)               administration/auteurs#enum_noms {:locale=>/fr|en|nl|it/}

What I have tried so far :

I don't know where to start looking to resolve this.

Upvotes: 2

Views: 196

Answers (2)

Veridian Dynamics
Veridian Dynamics

Reputation: 1406

I'm going to provide a slightly more articulate answer based on what I garnered from @thiebo.

<%= lieux.text_area :place, :value =>  params[:acte] ? @place["place"] : "",
     class:"field_places", data: {autocomplete_source: lieux_enum_path} %>

This field appears twice with the same field name. Delete the field without the autocomplete member on the data attribute.

Upvotes: 5

thiebo
thiebo

Reputation: 1435

For the sake of posterity, the problem had nothing to do with rails, routes or jquery. I had put elsewhere in the form another field with the same class name as the field on which I put the autocomplete.

Upvotes: 2

Related Questions