除了 image-url
和 Rails 4中的其他代码之外,我们还应该使用其他代码吗?它们返回的不同值似乎没有意义。如果我有 logo.png
在 /app/assets/images/logo.png
和我做以下,这是我得到的:
image-url("logo.png") -> url("/images/logo.png") #obviously doesn't work
image-path("logo.png") -> "/images/logo.png"
asset-url("logo.png") -> url("/logo.png")
当然,这些都不起作用,因为它们至少需要 /assets
在前面。
更新 : 实际上,我刚刚注意到,我如何在 Rails 4中访问图像?我在 /app/assets/images/logo.png
有图像。但是如果我访问以下任何一个 URL,我仍然看不到我的图像:
http://localhost:3000/assets/logo.png
http://localhost:3000/assets/images/logo.png
http://localhost:3000/logo.png
http://localhost:3000/images/logo.png
更新2 : 打开我的 logo.png
的唯一方法是将它移动到 /app/assets/stylesheets
目录,然后打开:
http://localhost:3000/assets/logo.png