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 –