2017-04-07 39 views
1

我有一張圖像被從表中的數據庫中拉出來,然後我想將它製作成一個鏈接,以便查看器可以看到完整的文章。我已經看到,在理論上我可以使用下面,使用從數據庫中的圖像路徑作爲link_to

<%= link_to image_tag('image/someimage.png') + "Some text", some_path %> 

但對我來說「圖像/ someimage.png」是

<%= image_tag coffeeshop.image_thumb_path %> 

我試着簡單地丟棄圖像標籤部分,所以它變成<%= link_to image_tag('image_tag coffeeshop.image_thumb_path') + "Some text", some_path %>但這不起作用。有沒有辦法做到這一點?

回答

2
link_to(body, url, html_options = {}) 

link_to第一個參數將被解釋爲標記的身體,然後你url,但如果你想添加更多的內容裏面link_to你可以打開它,然後將其關閉,所有內部將這樣解釋的:

<a href="#"> 
    ... 
</a> 

所以,你可以嘗試:

<%= link_to some_path do %> 
    <%= image_tag coffeeshop.image_thumb_path %> 
<% end %> 
相關問題