rails 4资产管道图像子目录 [英] rails 4 asset pipeline image subdirectories

查看:49
本文介绍了rails 4资产管道图像子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这可能是一个简单的问题,但是我很困惑.

I know this is probably an easy question but I am stumped here.

我正在处理的应用程序可以像这样放置资产:

The application I am working on houses assets like so:

app
--assets
----fonts
----images
----javascripts

我喜欢高效地组织资产,以免造成混乱,因此,我试图像这样分解图像:

I like to organize assets efficiently to avoid a mess down the road so I am trying to break up images like so:

app
--assets
----fonts
----images
------icons
------views
--------home
--------admin

理想情况下,我希望引用image.png之类的图像,而不必在诸如views/home/image.png之类的资产前面添加文件夹路径,尽管并非像开箱即用那样设置,但我相信这必须是可能的.

Ideally I would like to reference images like image.png without having to add the folder path in front of the asset like views/home/image.png which I believe has to be possible although not setup like that out of the box.

推荐答案

如果您将app/assets/images下的所有路径手动添加到application.rb中的Rails资产路径,则是可能的:

It's possible if you manually add all paths underneath app/assets/images to the Rails asset paths in your application.rb:

Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
  config.assets.paths << path
end

这篇关于rails 4资产管道图像子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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