rs19
rs19

Reputation: 667

add link_to to image tag with instance

I have the code below and I want to add the link to, as it is with the Gravatar, to the first line. It should link to user.

<section class="user_info">
      <% if @user.avatar.file? %>
        <div class="s3_avatar"> <%= image_tag @user.avatar.url(:square) %></div>
      <% else %>
        <%= link_to((gravatar_for @user, size: 100), @user ) %>
      <% end %>
      <h1>

Upvotes: 0

Views: 153

Answers (1)

Dharam Gollapudi
Dharam Gollapudi

Reputation: 6438

Instead of <%= image_tag @user.avatar.url(:square) %> try the following:

<%= link_to user_path(@user) do %>
  <%= image_tag @user.avatar.url(:square) %>
<% end %>

Refer to UrlHelper::link_to for more info.

Upvotes: 1

Related Questions