How to set-up jquery-ui autocomplete in Rails

后端 未结 7 1137
被撕碎了的回忆
被撕碎了的回忆 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:26

    Dale's Answer is quite the tutorial. One thing to note is that using your first query, the datasource will only return matches beginning with the string you type. If you want search anywhere in the word, you need to change:

    @people = Person.find(:all,:conditions =>
        ['given_name LIKE ?', "#{params[:term]}%"])
    

    to

    @people = Person.find(:all,:conditions =>
        ['given_name LIKE ?', "%#{params[:term]}%"])
    

    (added an extra % to the query)

提交回复
热议问题