我的文件存储在app/assets/images/subdirectory/image.png
和app/assets/images/subdirectory/image_full.png
。
在我的app/views/home.html.erb
:
<%= link_to (image_tag("subdirectory/image.png"), asset_path("subdirectory/image_full.png")) %>
我也试过了:
<%= link_to (image_tag("subdirectory/image.png"), asset_path("subdirectory/image_full.png", image)) %>
<%= link_to (image_tag("subdirectory/image.png"), image_path("subdirectory/image.png", image)) %>
无法通过文档找到更多内容:http://guides.rubyonrails.org/asset_pipeline.html
但是当我尝试加载视图时,它完全崩溃了我的应用程序!
如果还有一个paren,那么在link_to之后应该没有WHITESPACE:
<%= link_to(image_tag("subdirectory/image.png"), image_path("subdirectory/image_full.png", image)) %>
答案 0 :(得分:4)
<%= link_to image_path("subdirectory/image_full.png") do %>
<%= image_tag "subdirectory/image.png" %>
<% end %>
答案 1 :(得分:2)
尝试image_path
代替asset_path
,如下所示:
<%= link_to(image_tag("subdirectory/image.png"), image_path("subdirectory/image_full.png")) %>