所以,我认为这可能是我作为 JS 新手以及最近的 Rails 升级的问题。我正在尝试使用 Ryan Bates 的nested_form gem 创建一个复杂的动态嵌套表单。页面加载正常,看起来不错,但是当我单击“添加”和“删除”链接时,没有任何反应。将鼠标悬停在链接上会给我 javascript:void(0)。在 Chrome 中使用 JavaScript 观察者,我得到
Uncaught TypeError: Object #<HTMLDocument> has no method 'observe'
一些谷歌搜索告诉我,这意味着我与 Prototype 有冲突,但我没有在我的应用程序的任何地方使用 Prototype(或除 jQuery 之外的任何东西)。
这是我对相关信息的猜测。请告诉我我是否遗漏了什么。
我在 Ubuntu 12.04 LTS 上使用 rails 3.2.4 rc 1 和 ruby 1.9.3。
我的宝石文件:
source 'http://rubygems.org'
source 'http://gems.github.com'
gem 'rails', '3.2.4.rc1'
gem 'mysql'
gem 'execjs'
gem 'therubyracer'
gem 'nested_has_many_through'
gem 'validates_date_time'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'therubyracer', :platform => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails', '>= 1.0.12'
gem 'formtastic', :git => 'git://github.com/justinfrench/formtastic.git', :branch => '2.1-stable'
gem "nested_form", :git => 'git://github.com/ryanb/nested_form.git'
我的来自 application.js 的树
//= require jquery_ujs
//= require jquery
//= require jquery_nested_form
//= require_tree .
资产/javascripts的内容:
application.js
nested_form.js
rails.js
public/javascripts 中没有任何内容。
最后,这是控制台在页面加载期间输出的内容(它用于 Play 的编辑页面,其中 has_many Acts——我正在尝试使用 nested_form 添加和删除 Acts)
[2012-07-15 08:10:28] INFO WEBrick::HTTPServer#start: pid=23455 port=3000
Started GET "/acts/1/edit" for 127.0.0.1 at 2012-07-15 08:10:32 -0400
Processing by ActsController#edit as HTML
Parameters: {"id"=>"1"}
Act Load (3.5ms) SELECT `acts`.* FROM `acts` WHERE `acts`.`id` = ? ORDER BY act_number LIMIT 1 [["id", "1"]]
Play Load (0.7ms) SELECT `plays`.* FROM `plays` WHERE `plays`.`id` = 1 LIMIT 1
Scene Load (0.9ms) SELECT `scenes`.* FROM `scenes` WHERE `scenes`.`act_id` = 1 ORDER BY scene_number
Rendered acts/_scene_fields.erb (2.4ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.0ms)
Rendered acts/_scene_fields.erb (1.3ms)
Rendered acts/edit.html.erb within layouts/application (317.0ms)
Completed 200 OK in 558ms (Views: 407.1ms | ActiveRecord: 12.7ms)
[2012-07-15 08:10:33] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-07-15 08:10:33 -0400
Served asset /jquery.js - 304 Not Modified (30ms)
[2012-07-15 08:10:33] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/formtastic_changes.css?body=1" for 127.0.0.1 at 2012-07-15 08:10:33 -0400
Served asset /formtastic_changes.css - 304 Not Modified (3ms)
[2012-07-15 08:10:33] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/formtastic.css?body=1" for 127.0.0.1 at 2012-07-15 08:10:33 -0400
Served asset /formtastic.css - 304 Not Modified (5ms)
[2012-07-15 08:10:33] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/nested_form.js?body=1" for 127.0.0.1 at 2012-07-15 08:10:33 -0400
Served asset /nested_form.js - 304 Not Modified (3ms)
[2012-07-15 08:10:33] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-07-15 08:10:33 -0400
Served asset /application.css - 304 Not Modified (9ms)
[2012-07-15 08:10:33] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/scaffold.css?body=1" for 127.0.0.1 at 2012-07-15 08:10:33 -0400
Served asset /scaffold.css - 304 Not Modified (3ms)
[2012-07-15 08:10:33] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
我怀疑有什么我不小心打电话给某个地方的东西,或者什么……但我不知道。