Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Andrew Stelmach
12,583 PointsHow do I nest an image_tag inside a link_to?
I want to nest this:
<%= image_tag "logo.svg", id:"logo" %>
inside this:
<%= link_to root_path %>
inside one of my views (it's so users are taken to the home page when they click on my logo).
2 Answers

Maciej Czuchnowski
36,441 PointsThis should work:
<%= link_to root_path do %>
<%= image_tag "logo.svg", id:"logo" %>
<% end %>

Andrew Stelmach
12,583 PointsEven weirder is that when I tried it this time, it worked perfectly ;-)
Maybe the mystery is not the code, but my mind!!

Maciej Czuchnowski
36,441 PointsOr your browser is possessed by demons (in one of his videos, Nick Pettit mentioned that this sometimes happens, can't remember which video it was though).
Andrew Stelmach
12,583 PointsAndrew Stelmach
12,583 PointsDidn't work unfortunately. In Development, the image is there, but nothing happens on hover or click. Strangely, in Production (deployed to Heroku), it shows up as a broken image.
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsThat is weird, because I just tested this code locally in my own app:
And it works perfectly fine - displays and goes to root path on click, the html generated by these tags also looks perfectly fine. The image file is stored in the app/assets/images folder.
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsIf you tell me which branch this is on your github, I can take a look in deployment.