在 Rails 3.1 中添加新的资产路径 [英] Add a new asset path in Rails 3.1

查看:27
本文介绍了在 Rails 3.1 中添加新的资产路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在 Rails 3.1 中向资产管道添加另一个文件夹?

Does anyone know how to add another folder to the asset pipeline in Rails 3.1?

我想以与 app/assets/images 相同的方式提供 app/assets/fonts.

I'd like to serve app/assets/fonts the same way app/assets/images is served.

更新:2013 年 5 月 7 日

只是为将来发现此问题的人添加一些说明,以在您的 application.rb 文件中明确添加资产路径:

Just to add some clarification for future people who find this question to explicitly add an asset path, in your application.rb file:

config.assets.paths << "#{Rails.root}/app/assets/fonts"

但是,由于上述路径在 app/assets 下,您不必明确添加它,您只需要重新启动 Rails 应用程序,以便 Sprockets 可以获取它.

However, since the above path is under app/assets you don't have to add it explicitly, you just need to restart your rails app so Sprockets can pick it up.

您必须明确添加app/assetslib/assetsvendor/assets 之外的路径,并且只需请记住,虽然 Sprockets 会在您的应用程序加载时存在的文件夹中选取新文件,但根据我的经验,它不会在不重新启动的情况下选取资产路径中的新文件夹.

You will have to explicitly add paths that are outside of app/assets,lib/assets, or vendor/assets, and just remember that while Sprockets picks up new files in folders that were present when your application loaded, in my experience it does not pick up new folders in the asset paths without a restart.

推荐答案

Andrew,app/assets/fonts 实际上已经在你的资源加载路径中了,还有 images.所以你可以用同样的方式指向资产: <%= asset_path('/Ubuntu/Ubuntu-R-webfont.eot') %>[1] 或者你是怎样的引用您的图片.

Andrew, app/assets/fonts is actually already in your asset load path, along with images. So you can just point to the asset in the same way: <%= asset_path('/Ubuntu/Ubuntu-R-webfont.eot') %>[1] or how ever you are referencing your images.

我也花了一些时间来解决这个问题.我仍然不知道如果app/assets/fontsapp/assets/images 中存在同名文件会发生什么.

It took me a while to wrap my head around this as well. I still don't know what happens if there's a file with the same name in app/assets/fonts and app/assets/images.

[1] 假设你在 app/assets/fonts/Ubuntu/Ubuntu-R-webfont.eot

这篇关于在 Rails 3.1 中添加新的资产路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆