Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble displaying a clickable image in Rails

I'm new to Stackoverflow and new to Rails and I'm trying to display a clickable image in Rails. What I want to do is display the image, make it clickable and when you click on the image you can use the image viewer to zoom in. This works:

<%= link_to "Show Images", "image_path" %>

where image_path is a direct URL. When you click on the "Show Images" link, you're able to zoom in on the image. Instead of showing the text "Show Images" I want to show the image. I've tried this:

<%= link_to image_tag "image_path", "image_path" %>

But its giving me errors. I even tried putting parenthesies around the fields but it doesn't work. What am I doing wrong here? Thanks,

-LRC-

like image 539
user2292281 Avatar asked Mar 24 '23 06:03

user2292281


2 Answers

The following should work.

<%= link_to image_path do %>
    <%= image_tag image_path %>
<% end %>
like image 97
everett1992 Avatar answered Mar 26 '23 21:03

everett1992


If you put the parentheses like this, it should work:

<%= link_to image_tag("image_path"), "image_path" %>
like image 37
Wally Altman Avatar answered Mar 26 '23 20:03

Wally Altman