Serge Pedroza
Serge Pedroza

Reputation: 2170

link to the current_user via href

Currently I have a header that links the user to his profile through this:

<li><%= link_to '<i class="icon-picture"></i> My Profile'.html_safe, current_user %></li>

I would like to be able to link the current user to his profile by doing something like this:

<li>
  <a href="<%= current_user %>">
    <div><%= image_tag current_user.avatar (:small) %></div>
    &nbsp; <strong>Surge Pedroza</strong><br/>
    &nbsp; view my profile page
  </a>
</li>

But I do not know how to do it through an <a href="...">. Can someone please help me out?

Upvotes: 1

Views: 93

Answers (2)

Mischa
Mischa

Reputation: 43298

This would be a better way to accomplish what you want:

<%= link_to current_user do %>
  <div><%= image_tag current_user.avatar(:small) %></div>
  &nbsp; <strong><%= current_user.full_name %></strong><br/>
  &nbsp; view my profile page
<% end %>

link_to .. do is useful for the exact situation you are describing. Check the documentation for more examples.

Upvotes: 1

Serge Pedroza
Serge Pedroza

Reputation: 2170

I actually got it :)

<a href="<%= current_user.id %>">

Upvotes: 0

Related Questions