0
我正在嘗試使用rails的rails-jquery-autocomplete創建一個帶有自動完成功能的文本輸入字段。我試圖按照此頁上的說明逐步執行:https://github.com/bigtunacan/rails-jquery-autocomplete,但我無法使輸入字段顯示任何建議的文本。有人可以幫助我確定我做錯了什麼嗎?提前致謝。Rails 4:rails-jquery-autocomplete未顯示建議
下面是我的代碼片段:
控制器:
class LabController < ApplicationController
autocomplete :ingredient, :name
def index
@recipe = Recipe.where(station: "Laboratory")
end
end
查看:
.container
= autocomplete_field_tag 'test', '', autocomplete_ingredient_name_lab_index_path
路線:
resources :lab, only: [:index, :show] do
get :autocomplete_ingredient_name, :on => :collection
end
數據庫:
create_table "ingredients", force: :cascade do |t|
t.string "name", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
控制檯上是否有錯誤? – hgsongra
您可以使用令牌字段http://railscasts.com/episodes/258-token-fields代替'gem'rails-jquery-autocomplete'',它非常易於集成和輕量級。 – hgsongra
Hav你需要jQuery,jquery_ujs,jquery-ui/autocomplete,在你的application.js中使用自動完成軌道https://github.com/bigtunacan/rails-jquery-autocomplete#rails-4-and-higher –