使用 Ruby on Rails 3.1.2 我做了以下事情。
#app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .
对于 CSS 文件,我喜欢使用 @import 来更好地控制 CSS 文件的加载顺序。为此,我必须将 .scss 扩展名添加到 app/assets/stylesheets/application.css 文件以及我要导入的所有 CSS 文件中,例如 jQuery UI CSS 文件。
#app/assets/stylesheets/application.css.scss
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*/
@import "jquery-ui/ui-lightness/jquery-ui-1.8.16.custom.css.scss";
/* Other css files you want to import */
@import "layout.css.scss";
@import "home.css.scss";
@import "products.css.scss";
....
然后我将所有与 jQuery UI 相关的内容放在 vendor/assets 中,如下所示:
jQuery UI 样式表:
vendor/assets/stylesheets/jquery-ui/ui-lightness/jquery-ui-1.8.16.custom.css.scss
jQuery UI 图片文件夹:
vendor/assets/images/images
请注意,您可以像我在此处使用“jquery-ui/ui-lightness”路径所做的那样在样式表路径中创建其他文件夹。这样您就可以将多个 jQuery 主题很好地分开保存在各自的文件夹中。
** 重新启动服务器以加载任何新创建的加载路径 **
Ryan Bates 有一些关于资产管道和 Ruby on Rails 3.1 中的Sass 的精彩截屏视频,其中他展示了如何在 Sass 中使用 @import 函数。在这里观看:
编辑:我忘了提到这在本地和Heroku 上都可以在Cedar stack 上工作。