[英]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.