How to set-up jquery-ui autocomplete in Rails

后端 未结 7 1111
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 09:55

I need some help on how to implement a jquery-ui autocomplete in my Rails app.

I want to add autocompletion to a text field where the user can enter in a customer na

相关标签:
7条回答
  • 2020-11-27 10:34

    Since this is old, but google still comes here, a small note about the main answer, which is essentially good, but some things have changed:

    • see answer about jquery having changed .data("uiAutocomplete") to .data("autocomplete")

    • Also i would recommend a separate route on the resource collection that just handles json

    • use rabl to create smaller json (or pluck for larger models)
    • ilike , not like, for case insensitive
    • the % in front, so the search is not just start_with.
    • valiable traversal in the methods, like item.person.name are just item.name (so drop the .person)
    • use coffee (in haml)
    • use a limit, and where as in: Person.where('given_name ilike ?', "%#{params[:term]}%").limit(20)
    0 讨论(0)
提交回复
热议问题