次の質問に似た問題が発生しています: Rails asset pipeline not included required files in application.js manifestただし、その質問はクローズされたので、状況の詳細とともに再質問します。)
環境:
ルビー 2.0.0、レール 3.2.8、OSX 10.7.5、クローム 28.0.1500.95
私が経験している主な問題
「/app/assets/javascripts」に配置されたファイルは、「/public/assets」にコンパイルまたは表示されないようです
例
この test.js ファイルのようなファイルを app/assets/javascripts に配置すると:
alert("Hello!");
アプリでページをリロードすると、このアラートが表示されます。( Railscast でアセット パイプラインの ~6:30 にRyan Bates が行っていることをビデオに複製しています) ただし、アラートは表示されません。
デバッグの試み
これをデバッグするために行ったいくつかのテスト。
- (以下の @Aidan の推奨に従って) 「rm -rf public/assets」を実行し、レイアウトに「javascript_include_tag 'test'」を追加すると、アラートが 表示されます。ただし、おそらく私は初心者なので、問題のデバッグにどのように役立つかわかりません。
- //= require_test to app/javascripts/application.js をマニフェスト ファイルに追加しても、アラートは表示されません。
マイ マニフェスト ファイル (app/javascripts/application.js)
// 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ファイル
# Enable the asset pipeline
config.assets.enabled = true
「y Rails.application.config.assets.paths」の Rails コンソール出力
"/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 ファイル
!!! 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 で表示されたアプリ ページからのソース
<!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」を表示したときに表示されるもの
/*!
* 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 ファイルが表示されないようにする必要がありますか?
問題が何であるかについて何か提案はありますか? この問題のデバッグに役立つ追加情報はありますか? 助けてくれてありがとう!