我正在使用 jquery-autocomplete-rails 尝试动态填充现有机柜的下拉列表,以便在用户创建新设备时进行选择。我希望显示cabinet.names 但捕获表单所选项目的cabinet.id。
表单标签:
<%= autocomplete_field_tag 'cabinet', '', cabinets_autocomplete_cabinet_name_path %>
<% f.hidden_field :cabinet_id, :id => "real cabinet id" %>
设备和机柜控制器的开头:
class DevicesController < ApplicationController
autocomplete :device, :cabinet, :name
...
end
class CabinetsController < ApplicationController
autocomplete :cabinet, :name
...
end
来自 routes.rb 的相关路线:
get 'devices/autocomplete_cabinet_name'
get 'cabinets/autocomplete_cabinet_name'
看起来命令没有失败,但是当我开始输入表单(在本例中为 0055)时,控制台会显示以下内容:
Started GET "/cabinets/autocomplete_cabinet_name?term=0055-" for 127.0.0.1 at 20
13-04-03 10:45:08 -0400
Processing by CabinetsController#show as JSON
Parameters: {"term"=>"0055-", "id"=>"autocomplete_cabinet_name"}
←[1m←[36mUser Load (1.0ms)←[0m ←[1mSELECT `users`.* FROM `users` WHERE `users
`.`id` = 2 LIMIT 1←[0m
←[1m←[35mCabinet Load (5.9ms)←[0m SELECT `cabinets`.* FROM `cabinets` WHERE (
name LIKE '%0055-%')
Completed 200 OK in 52ms (Views: 1.0ms | ActiveRecord: 6.8ms)
我猜用户查询与我的登录有关。
我已经使用以下资源寻求帮助: https ://github.com/crowdint/rails3-jquery-autocomplete-app 对上一个教程的许多更正都在这里: rails3-jquery-autocomplete
如果可以,请提供帮助。谢谢你。