我正在将应用程序从 Rails 3.0 迁移到 Rails 3.1。我更改了所有必要的配置文件并安装了 gem(在 Ryan 的截屏视频的帮助下)。我的布局很少,我想为它们加载不同的脚本。
我有观点:
布局/console.html.erb
<html lang="ru">
<head>
...
<%= stylesheet_link_tag "console" %>
<%= yield :stylesheets%>
<%= javascript_include_tag 'console' %>
...
<%= yield :javascripts%>
</head>
</html>
在我的资产中,我创建了文件 console.js:
资产/javascripts/console.js
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_self
//= require_tree ./console
我还使用此文件夹内的文件创建了文件夹控制台:
资产/javascripts/控制台/users.js.coffee
jQuery ->
alert "Test"
但是当我加载这样的页面警报时不会出现。
当我调试页面时,我看到 Rails 加载了这个
<script type="text/javascript" src="/assets/console.js?body=1"></script>
其中包含:
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
;
还有这个:
<script type="text/javascript" src="/assets/console/users.js.coffee ?body=1"></script>
其中包含:
jQuery ->
alert "Test"
;
我的问题是什么?我怎样才能解决这个问题?
UPD:页面头部的链接:
<head>
...
<meta charset="utf-8">
<meta name="csrf-param" content="authenticity_token">
<meta name="csrf-token" content="PAO2QZ6Z3ykmksXnY55dmCehq+i2COXmSlnZWjErFwA=">
<link type="image/vnd.microsoft.icon" rel="shortcut icon" href="/favicon.ico">
<link type="text/css" rel="stylesheet" media="screen" href="/assets/console.css?body=1">
<link type="text/css" rel="stylesheet" media="screen" href="/assets/console/console.css?body=1">
<link type="text/css" rel="stylesheet" media="screen" href="/assets/console/pagination.css?body=1">
<link type="text/css" rel="stylesheet" media="screen" href="/assets/console/search-form.css?body=1">
<script type="text/javascript" src="/assets/jquery.js?body=1"></script>
<script type="text/javascript" src="/assets/jquery_ujs.js?body=1"></script>
<script type="text/javascript" src="/assets/console.js?body=1"></script>
<script type="text/javascript" src="/assets/console/users.js.coffee ?body=1"></script>
</head>