I have the following:
<%=link_to( image_tag(participant.user.profile_pic.url(:small)), :class=>"work") %>
which outputs the following:
<a href="/xxxx/308?class=work"><img alt="xxxx" src="xxxxx"></a>
I want the class "work" to be a class for the a href not a query param, so it should look like:
<a href="/xxxx/308" class="work">
is this possible?
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 %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With