THpubs
THpubs

Reputation: 8172

How to add HTML code into a link_to tag in rails?

This is my link_to tag :

<%= link_to "Signout", dasharea_signout_path, method: "delete", id: "adminsignout"  %>

I need to add

<i class="fa fa-tasks">

into the 'a' tag created by the above code. How can I do this?

Upvotes: 0

Views: 1529

Answers (2)

Carlos Ramirez III
Carlos Ramirez III

Reputation: 7434

You can pass a block to the link_to helper

<%= link_to dasharea_signout_path, method: "delete", id: "adminsignout" do %>
  <i class="fa fa-tasks"></i>
  <span>Signup</span>
<% end %>

The block content will be wrapped in the link tag.

Upvotes: 5

Raghuveer
Raghuveer

Reputation: 2637

You can do like below:

<%= link_to "Signout <i class='fa fa-tasks'></i>", dasharea_signout_path, method: "delete", id: "adminsignout"  %>

OR in HAML

%a#adminsignout{other properties}
  Signout
  %i.fa.fa-tasks

Upvotes: 0

Related Questions