我一直在将应用程序转换为Rails 3.1(现在转到3.2)并在资产管道上观看Railscast.我将所有第三方jquery插件文件移动到/ vendor/assets/javascripts /目录.在我的/app/assets/javascripts/application.js中,我有以下内容:
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require_self
Run Code Online (Sandbox Code Playgroud)
我意识到require_tree .调用只加载/ app/assets/javascripts /目录的树.(这是正确的吗?)包含所有 "供应商"javascripts 的最佳方式是什么?(我现在并不担心订购.)当然,我可以在/app/assets/javascripts/application.js中逐行索取.我的另一个想法是使用以下内容创建/vendor/assets/javascripts/vendor_javascripts.js:
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
然后在/app/assets/javascripts/application.js中添加以下内容:
//= require vendor_javascripts
Run Code Online (Sandbox Code Playgroud)
这看起来有点笨拙.有没有更好的方法来自动包含所有"供应商"(和/或"lib")javascripts?
PS.我看到了关于index.js文件的内容,但我最终可能会得到多个名为index.js的文件,对吧?哦,我尝试重新启动我的服务器.
我遇到了类似于这个问题的问题: Rails资产管道不包括application.js中的必需文件然而,这个问题已经关闭,所以我重新询问它,但是我的具体情况.)
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!");
Run Code Online (Sandbox Code Playgroud)
然后在我的应用程序中重新加载页面,此警报应该出现.(我正在复制Ryan Bates在资产管道上的Railscast中在~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.
//
// …Run Code Online (Sandbox Code Playgroud) 当我试图包括
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
Run Code Online (Sandbox Code Playgroud)
application.css的文件内容是:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, …Run Code Online (Sandbox Code Playgroud)