Ruby on Rails using link_to with image_tag
Where are you providing the HREF, the path that must be retrieved when someone click's the image? link_to is being kind and assuming it to be the current path. Ideally you would provide, the path as the second option to link_to.
<%=link_to( image_tag(participant.user.profile_pic.url(:small)), :class=>"work") %>
<%=link_to( image_tag(participant.user.profile_pic.url(:small)), user_path(participant.user), :class=>"work") %>
You should not rely on an empty hash as the second parameter, but explicitly provide the path you want to go to when image is clicked.
The above answer didn't work for me. Maybe a different version of rails?
I'm using Rails 4 and this worked:
<%= link_to (image_tag (participant.user.profile_pic.url (:small)), class: 'work'), user %>
In Rails 6:
<%= link_to root_path do %>
<%= image_tag("A_logo_black.png", alt: 'Logo',class: 'h-16')%>
<% end %>
where you have a root path defined in your routes.rb
file:
Rails.application.routes.draw do
root to: 'dashboard#index'
end