Nicholas Hazel
Nicholas Hazel

Reputation: 3740

Rails - Link a thumbnail image to a larger full image

I'm new to Rails and I'm trying to decipher how to link an image to open a different image (thumbnail vs large image, and they aren't the same).

I've tried:

    <%= link_to "fullNews.jpg" do %>
      <% image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
    <% end %>

As well as trying to use erb inside of erb:

    <%= link_to "<% image_tag("fullNews.jpg") %>" do %>
      <% image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
    <% end %>

Even a direct link:

    <%= link_to "assets/images/fullNews.jpg" do %>
      <% image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
    <% end %>

I'm sure it's just a syntax thing but I can't figure out how to achieve this?

Upvotes: 3

Views: 844

Answers (1)

Igor Pantović
Igor Pantović

Reputation: 9246

Pretty easy:

<%= link_to image_url("fullNews.jpg") do %>
      <%= image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
<% end %>

Upvotes: 2

Related Questions