Search code examples
ruby-on-railsdeviselink-to

Rails How to have Link to + Icon both on the same line & clickable


I want to make it so that I have the logout icon and the link to logout on the same line and as the same clickable link.

If I do it this way:

<li>
  <span><i class="fa fa-sign-out"></i> <%= link_to "Sign Out", destroy_user_session_path, method: :delete %></span>
</li>

I get the icon on a separate line and the icon is not clickable to get to the link.

This is how I did it for the login, since I have a get /login page:

<li>
  <a href="/login">
   <i class="fa fa-user"></i>
   <span>Edit Account</span>
  </a>
</li>

I am using devise to the login and logout. How could I get it so that the icon and the text and both clickable and on the same line for the signout link since the signout link is a delete and not get.


Solution

  • When using link_to, you can pass block

    <li>
      <%= link_to destroy_user_session_path, method: :delete do %>
        <span>
          <i class="fa fa-sign-out"></i>
          Sign Out
        </span>
      <% end %>
    </li>