【发布时间】:2011-12-23 09:46:35
【问题描述】:
我正在尝试在 Rails 3.1 下实现自动完成功能。
https://github.com/crowdint/rails3-jquery-autocomplete
我一直在关注这个完整的应用示例并更改 Rails 3.1 的相关部分,但它仍然无法正常工作。
https://github.com/crowdint/rails3-jquery-autocomplete-app
这是我的 applicaion.js 文件
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
//= require_tree .
我已经下载了 jquery 1.8.16(勾选了自动完成功能),解压缩并将 js 复制到我的 app/assets/javascript 目录中,并将 css 和图像目录复制到 app/assets/stylesheets 中。
然后我创建了一个链接,以便我可以将其引用为 jquery-ui
ln -s jquery-ui-1.8.16.custom.min.js jquery-ui.js
与 CSS 相同
ln -s jquery-ui-1.8.16.custom.css jquery-ui.css
然后我在 application.css 中放了一个指向我的 css 的链接
*= require_self
*= require jquery-ui
*= require_tree .
我创建了品牌模型并像示例一样迁移并添加了种子数据。
然后我按照教程将以下行添加到我的欢迎控制器中:
autocomplete :brand, :name
我修复了 routes.rb 文件并编辑了表单。
我得到的是没有自动完成功能的表单,我的服务器输出也没有错误:
% rails s -p 3001
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3001
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-07 16:35:53] INFO WEBrick 1.3.1
[2011-11-07 16:35:53] INFO ruby 1.9.2 (2011-02-18) [x86_64-linux]
[2011-11-07 16:35:53] INFO WEBrick::HTTPServer#start: pid=12616 port=3001
Started GET "/" for 127.0.0.1 at 2011-11-07 16:35:54 +1100
Processing by WelcomeController#show as HTML
Rendered welcome/show.html.erb within layouts/application (15.7ms)
Completed 200 OK in 98ms (Views: 75.6ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/jquery-ui.css?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /jquery-ui.css - 304 Not Modified (5ms)
Started GET "/assets/jquery-ui-1.8.16.custom.css?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /jquery-ui-1.8.16.custom.css - 304 Not Modified (1ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /jquery.js - 304 Not Modified (1ms)
Started GET "/assets/welcome.css?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /welcome.css - 304 Not Modified (2ms)
Started GET "/assets/jquery-ui.js?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /jquery-ui.js - 304 Not Modified (5ms)
Started GET "/assets/jquery-ui-1.8.16.custom.min.js?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /jquery-ui-1.8.16.custom.min.js - 304 Not Modified (3ms)
Started GET "/assets/welcome.js?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /welcome.js - 304 Not Modified (2ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /application.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /jquery_ujs.js - 304 Not Modified (1ms)
Started GET "/assets/autocomplete-rails.js?body=1" for 127.0.0.1 at 2011-11-07 16:35:55 +1100
Served asset /autocomplete-rails.js - 304 Not Modified (1ms)
我在这里缺少什么? 是否有更新的 Rails 3.1 插件或更好的教程?
【问题讨论】:
标签: jquery ruby-on-rails-3 jquery-ui autocomplete