我遇到了类似这个问题的问题: Rails asset pipeline not including required files in application.js manifest然而,这个问题已经结束,所以我会重新询问,但是我的具体情况。)
Ruby 2.0.0,Rails 3.2.8,OSX 10.7.5,Chrome 28.0.1500.95
放置在“/ app / assets / javascripts”中的文件似乎没有编译或出现在“/ public / assets”中
如果我在app / assets / javascripts中放置一个这样的test.js文件:
alert("Hello!");
然后在我的应用中重新加载页面,此警报应该会出现。 (我正在复制Ryan Bates在他的Railscast on the Asset Pipeline中以约6:30的时间对视频进行的操作)但是,没有出现警报。
我尝试调试此操作的一些测试。
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
// removed /sitewide from require_tree
//
// 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_tree .
# Enable the asset pipeline
config.assets.enabled = true
"/Users/Anders/Dropbox/dev/suggestion-box-app/app/assets/images",
"/Users/Anders/Dropbox/dev/suggestion-box-app/app/assets/javascripts",
"/Users/Anders/Dropbox/dev/suggestion-box-app/app/assets/stylesheets",
"/Users/Anders/.rvm/gems/ruby-2.0.0-p195@suggestion-box-app/gems/coffee-rails-3.2.2/lib/assets/javascripts",
"/Users/Anders/.rvm/gems/ruby-2.0.0-p195@suggestion-box-app/gems/jquery-rails-3.0.4/vendor/assets/javascripts"
!!! 5
%html
%head
%meta{:charset => "utf-8"}/
%meta{:content => "width=device-width", :name => "viewport"}/
%meta{:content => "yes", :name => "apple-mobile-web-app-capable"}/
%title My App
%script{:type=>"text/javascript", :src=>"//use.typekit.net/wjb6ybj.js"}
:javascript
try{Typekit.load();}catch(e){}
= stylesheet_link_tag "screen", :media => "all"
= csrf_meta_tags
= javascript_include_tag "application"
%body
#container
= render "layouts/flashes"
= yield
= render "layouts/footer"
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta content='width=device-width' name='viewport'>
<meta content='yes' name='apple-mobile-web-app-capable'>
<title>My app</title>
<script src='//use.typekit.net/wjb6ybj.js' type='text/javascript'></script>
<script>
try{Typekit.load();}catch(e){}
</script>
<link href="/assets/screen.css?body=1" media="all" rel="stylesheet" type="text/css" />
<meta content="authenticity_token" name="csrf-param" />
<meta content="FqMtH+rs6or9HRx+RL4bWpQyLTNPM8BKLrcf/xZknP8=" name="csrf-token" />
<script src="/assets/application.js?body=1" type="text/javascript"></script>
</head>
<body>
<div id='container'>
....
</div>
</body>
</html>
/*!
* jQuery JavaScript Library v1.9.1
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2005, 2012 jQuery Foundation, Inc. and other contributors
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2013-2-4
*/
(function(e,t){function P(e){var t=e.length,n=b.type(e);return b.isWindow(e)?!1:e.nodeType===1&&t?!0:n==="array"||n!=="function"&&(t===0||typeof t=="number"&&t>0&&t-1 in e)}function B(e){var t=H[e]={};return b.each(e.match(E)||[],function(e,n){t[n]=!0}),t}function I(e,n,r,i){if(!b.acceptData(e))return;var s,o,u=b.expando,a=typeof n=="string",f=e.nodeType,c=f?
[...除去jquery的剩余部分]
我不应该在这里看到test.js文件吗?
有关问题可能是什么的任何建议?我可以提供任何其他信息来帮助调试此问题吗?谢谢你的帮助!
答案 0 :(得分:11)
问题似乎与我的rails / gem版本有关。在从Rails 3.2.8更新到Rails 3.2.14(还需要将机架gem从1.4.1更新到1.4.5)后,问题得到了解决,资产/ javascripts中的项目现在正在编译/添加到公共/资产中。请注意,我创建了一个全新的gemset作为其中的一部分,因此该问题可能与Rails版本无关,只是一个需要重新创建的“损坏”宝石集的问题。
答案 1 :(得分:2)
Rails将编译config.assets.precompile
中列出的所有目标。这些目标将编译为public/assets/
。该配置项已包含"application.js"
和其他一些目标,因此您需要将要预编译的任何其他目标添加到public/assets/
。要为任何特定目标编译的源文件将根据目标名称自动计算;例如,test.js
的目标将从app/assets/javascripts/test.js
或app/assets/javascripts/test.js.coffee
编译,以存在者为准。