Rails 3 - assets / javascripts中的jquery未在页面加载时运行

时间:2012-05-19 15:12:16

标签: jquery ruby-on-rails ruby-on-rails-3

我刚刚设置了rails,我已经设置了自定义索引页面,从资产/样式表中获取了CSS,我的javascript正在使用assets / javascripts。

如果我把它放在我的index.html中的'script'标签内,或者如果我从Firebug控制台运行一些随机的jQuery代码,jQuery也可以工作。

但是,在assets / javascripts中的js文件中,页面加载时没有执行Jquery代码。知道为什么吗?

我怀疑它可能与我的页面加载不同文件的顺序有关,但我无法看到任何可以检查或修复它的地方。

我在我的application.js -

中有这个
//= require jquery
//= require jquery_ujs
//= require_tree .

如果它是相关的

,我已经在我的布局文件的头部中得到了这个
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag    "application", :media => "all" %>
<%= csrf_meta_tags %>

这是我的服务器登录页面加载的输出 -

Started GET "/" for 192.168.2.3 at Sat May 19 15:58:47 +0100 2012
Processing by HomeController#index as HTML
Rendered home/index.html within layouts/application (0.1ms)
Compiled application.js  (8ms)  (pid 15001)
Completed 200 OK in 158ms (Views: 157.7ms | ActiveRecord: 0.0ms)


Started GET "/assets/jquery.js?body=1" for 192.168.2.3 at Sat May 19 15:58:51 +0100   2012
Served asset /jquery.js - 304 Not Modified (0ms)


Started GET "/assets/jquery_ujs.js?body=1" for 192.168.2.3 at Sat May 19 15:58:51 +0100 2012
Served asset /jquery_ujs.js - 304 Not Modified (0ms)


Started GET "/assets/home.js?body=1" for 192.168.2.3 at Sat May 19 15:58:51 +0100 2012
Served asset /home.js - 304 Not Modified (0ms)


Started GET "/assets/application.js?body=1" for 192.168.2.3 at Sat May 19 15:58:51 +0100 2012
Served asset /application.js - 304 Not Modified (22ms)


Started GET "/assets/application.css?body=1" for 192.168.2.3 at Sat May 19 15:58:51 +0100 2012
Served asset /application.css - 304 Not Modified (0ms)


Started GET "/assets/home.css?body=1" for 192.168.2.3 at Sat May 19 15:58:51 +0100 2012
Served asset /home.css - 304 Not Modified (0ms)

我没有在Firebug中出现任何错误,或者任何暗示它无法正常工作的错误。

0 个答案:

没有答案