How to get Jquery UI Autocomplete working with Rails 4?

前端 未结 2 1717
感动是毒
感动是毒 2020-12-09 20:08

I\'m using Rails 4.0.2 with jquery-rails (3.1.0) and jquery-ui-rails (4.1.1) gems. I\'m trying to add Autocomplete to the search form (using Bootstrap 3.1.0):



        
相关标签:
2条回答
  • 2020-12-09 20:26

    Judging by your note, it looks like you're not fetching the param correctly in your controller, so try:

    render json: @products.where("name ILIKE ?", "%#{params[:term]}%")

    0 讨论(0)
  • 2020-12-09 20:36
      def autocomplete
        @products = Product.order(:name).where("name LIKE ?", "%#{params[:term]}%")
        respond_to do |format|
          format.html
          format.json { 
            render json: @products.map(&:name).to_json
          }
        end
      end
    
    0 讨论(0)
提交回复
热议问题