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

查看:50
本文介绍了在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/fontsimages实际上已经在您的资产加载路径中.因此,您可以使用相同的方式指向资产:<%= 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天全站免登陆