1

I want to create a link(HTML Anchor Tag) that contains an img Tag element in my application. I used link_to to produce links but don't know how to generate HTML tags within them.

Do i need to use javascript/jQuery rather than trying it in my application. Any suggestions would be appreciated.

Here it should look like

<a href='/groceries'>
   <img src="location" alt="Groceries.jpg">
</a>
bhanu
  • 2,260
  • 3
  • 24
  • 35

1 Answers1

1

You can find this in documentation, anchor seems as:

<%= link_to "Comment wall", profile_path(@profile, anchor: "wall") %>

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

For your case:

<%= link_to groceies_path(anchor: 'header') do %>
  <%= image_tag('test.png', alt: 'Grocieries') %>
<% end %>
itsnikolay
  • 17,415
  • 4
  • 65
  • 64