为什么我的rails资产管道中的js文件没有被编译? [英] Why are js files in my rails asset pipeline not being compiled?
问题描述
我遇到类似这个问题的问题:
Rails资产管道不包括application.js清单中的必需文件然而,这个问题已经关闭,所以我重新询问它,但是我的具体情况。)
I am experiencing a problem similar to this question: Rails asset pipeline not including required files in application.js manifest However, that question was closed, so I am re-asking it, but with the specifics of my situation.)
Ruby 2.0.0,Rails 3.2.8,OSX 10.7.5,Chrome 28.0.1500.95
Ruby 2.0.0, Rails 3.2.8, OSX 10.7.5, Chrome 28.0.1500.95
放在/ app / assets / javascripts中的文件似乎不是编译或出现在/ public / assets中
Files placed in "/app/assets/javascripts" do not appear to be compiling to or appearing in "/public/assets"
如果我放置一个文件,如app / assets / javascripts中的这个test.js文件:
If I place a file such as this test.js file in app/assets/javascripts:
alert("Hello!");
然后在我的应用程序中重新加载页面,此警报应该出现。 (我正在复制Ryan Bates在他的资产管道上的Railscast 大约在6:30进入视频)但是,没有出现警告。
and then reload a page in my app, this alert should appear. (I am replicating what Ryan Bates does in his Railscast on the Asset Pipeline at ~6:30 into the video) However, no alert appears.
一些测试我试着调试这个。
Some tests I did to try to debug this.
- (正如@Aidan下面推荐的那样)如果我rm -rf public / assets,那么
在我的布局中添加javascript_include_tag'test',警告
出现。但是,也许是因为我是n00b,我不知道
如何帮助我调试问题。 - 如果我将// = require_test添加到app / javascripts / application.js到我的
清单文件,这会导致警报出现而不是 。
- (As recommended by @Aidan below) If I "rm -rf public/assets", then add "javascript_include_tag 'test'" to my layout, the alert does appear. However, maybe because I'm a n00b, I don't know how that helps me debug the problem.
- If I add //= require_test to app/javascripts/application.js to my manifest file, this does not result in the alert appearing.
// 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 .
我的application.rb文件
My application.rb file
# Enable the asset pipeline
config.assets.enabled = true
Rails控制台输出y Rails.application.config.assets.paths
Rails console output for "y Rails.application.config.assets.paths"
"/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"
我的观点/布局/ application.html.haml file
My views/layouts/application.html.haml file
!!! 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"
来自在localhost中查看的应用页面的来源:3000
Source from an app page viewed in localhost:3000
<!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>
查看localhost:3000 / assets / application.js时看到的内容
What I see when viewing "localhost:3000/assets/application.js"
/*!
* 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的剩余部分]
[...remainder of jquery excluded]
我不应该看到test.js文件在这里?
有关问题可能是什么的任何建议?我可以提供任何其他信息来帮助调试此问题è?感谢您的帮助!
Any suggestions as to what the problem might be? Is there any additional info I can provide to help debug this issue? Thanks for any help!
推荐答案
问题似乎与我的rails / gem版本有关。在从Rails 3.2.8更新到Rails 3.2.14(还需要将机架gem从1.4.1更新到1.4.5)后,问题得到了解决,资产/ javascripts中的项目现在正在编译/添加到公共/资产中。请注意,我创建了一个全新的gemset作为其中的一部分,因此该问题可能与Rails版本无关,只是一个需要重新创建的损坏宝石集的问题。
The problem appears to have been related to my rails/gem versions. After updating from Rails 3.2.8 to Rails 3.2.14 (which also required updating the rack gem from 1.4.1 to 1.4.5) the issue was resolved and items in assets/javascripts are now being compiled/added to public/assets. Note that I created a completely new gemset as part doing this, so the issue may have had nothing to do with the Rails version and simply was a questions of a "corrupted" gem set that needed to be re-created.
这篇关于为什么我的rails资产管道中的js文件没有被编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!