Rails 4 link_to更大的静态图像

时间:2014-01-08 07:50:39

标签: heroku ruby-on-rails-4 asset-pipeline

我的文件存储在app/assets/images/subdirectory/image.pngapp/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

但是当我尝试加载视图时,它完全崩溃了我的应用程序!

ANSWER

如果还有一个paren,那么在link_to之后应该没有WHITESPACE:

<%= link_to(image_tag("subdirectory/image.png"), image_path("subdirectory/image_full.png", image)) %>

2 个答案:

答案 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")) %>