[英]How to add IMG with in ANCHOR while using link_to in Rails?
我想在我的應用程序中創建一個包含img Tag元素的鏈接(HTML錨標簽)。 我使用link_to來生成鏈接,但是不知道如何在其中生成HTML標簽。
我需要使用javascript / jQuery而不是在我的應用程序中嘗試它嗎? 任何建議,將不勝感激。
在這里看起來像
<a href='/groceries'>
<img src="location" alt="Groceries.jpg">
</a>
您可以在文檔中找到它,錨點顯示為:
<%= link_to "Comment wall", profile_path(@profile, anchor: "wall") %>
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
對於您的情況:
<%= link_to groceies_path(anchor: 'header') do %>
<%= image_tag('test.png', alt: 'Grocieries') %>
<% end %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.