ですから、これは私がJSの初心者であり、最近のRailsのアップグレードでもあるという問題かもしれません。RyanBatesのnested_formgemを使用して、複雑で動的なネストされたフォームを作成しようとしています。ページは正常に読み込まれ、正常に表示されますが、[追加]リンクと[削除]リンクをクリックしても何も起こりません。リンクにカーソルを合わせると、javascript:void(0)が表示されます。ChromeでJavaScriptオブザーバーを使用すると、
Uncaught TypeError: Object #<HTMLDocument> has no method 'observe'
いくつかのグーグルは、これは私がPrototypeと競合していることを意味しますが、アプリケーションのどこでもPrototype(またはjQuery以外のもの)を使用していないことを示しています。
これが関連情報の私の推測です。何か忘れてしまったら教えてください。
Ubuntu12.04LTSでrails3.2.4rc1とruby1.9.3を使用しています。
私のgemfile:
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 .
アセット/JavaScriptの内容:
application.js
nested_form.js
rails.js
public/javascriptsには何もありません。
最後に、ページの読み込み中にコンソールが出力するものは次のとおりです(これは、Playの編集ページ用であり、多くの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
誤ってどこかで呼んでいるものがあるのではないかと思いますが…わかりません。