何时将图像放入 app/assets 以及何时将/public/images 放入 rails 3.1? [英] when to put images to app/asssets and when to /public/images in rails 3.1?

查看:53
本文介绍了何时将图像放入 app/assets 以及何时将/public/images 放入 rails 3.1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然不太明白,在这些情况下,将图像放在 rails 3.1 的何处:

I still don't quite get it, where to put images in rails 3.1, in these situation:

  1. 图像经过处理(例如通过回形针或蜻蜓)并存储在文件夹中(而不是使用 s3 等外部服务,..f.e. 正在开发中)
  2. 当我只有图像时,我将在样式表中使用(例如背景)
  3. 图标(AppStore、Facebook ...)

谢谢

推荐答案

Stylesheet 图片应该放在 app/assets 中,而通过 paperclip 上传的文件应该放在 public/system 中.对于 assets ,将为每个文件创建指纹,因此可以正确缓存它们.如果缓存文件发生变化,指纹也会发生变化,这样缓存就会失效.

Stylesheet images should be placed in app/assets, while files uploaded by paperclip in public/system. In case of assets , fingerprints will be created for every file, so they can be properly cached. If cached file changes, fingerprint changes too and in such way cache is invalidated.

更新:要引用 app/assets 中的文件(例如在 css 中指定图像 url),您需要使用特殊的资产管道 ERB 或 SCSS 助手(例如 image-pathimage-url> 用于 SCSS,asset_path 用于 ERB).

UPDATE: To reference files in app/assets (e.g. specifying image url in css) you`ll need to use special asset pipeline ERB or SCSS helpers (like image-path and image-url for SCSS and asset_path for ERB).

这篇关于何时将图像放入 app/assets 以及何时将/public/images 放入 rails 3.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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