How to set-up jquery-ui autocomplete in Rails

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

    I basically followed Dale's advice below but my controller and js files were slightly diff- his version was giving me issues for some reason (maybe bc of jquery updates)

    Context: I'm trying to autocomplete names of DJs typed in by users - also a newb

    DJs Controller

     class DjsController < ApplicationController
        def index
         if params[:term]
           @djs = Dj.is_dj.where('lower(name) LIKE ?', "%#{params[:term].downcase}%")
           respond_to do |format|  
              format.html
              format.json { render :json => @djs.map(&:name) }
           end
         end    
       end
     end
    

    html.erb file

      
    

提交回复
热议问题