Rails 小坑,静态文件调用方法 asset_path

as181920 · May 02, 2013 · Last by Tony612 replied at May 02, 2013 · 2667 hits

以前图片等习惯了用

<%=image_tag "/assets/xxx.jpg"%>

现在用 rails 最新版本(基于 git),发现这样会找不到图片,改成如下就好了

<%=image_tag asset_path("xxx.jpg")%>

而且以前 precompile 似乎有个源文件 copy 到 public 下,现在全部是带 digit 后缀的文件。

有知道缘故的可以再给提醒下,让了解个所以然:)

为什么是 <%=image_tag "/assets/xxx.jpg"%> 而不是<%=image_tag "xxx.jpg"%> ?,应该后者这种就可以了吧。 BTW,没怎么用asset_path这个 helper,一般使用 scss 的话,应该都用image-urlimage-path了吧。 可以看这里: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

You need to Sign in before reply, if you don't have an account, please Sign up first.