suyesh
suyesh

Reputation: 530

How to use the tags and classes in link_to helper

Here is the code for my link:

<%=link_to "My Stations", retailer_my_stations_path%>

I want to style the link like:

<a class="dropdown-collapse" href="#"><i class='icon-edit'></i>
    <span>My Stations</span>
</a>

How do I make Rails' link_to helper use the Icon <i> tag and the "My Stations" be inside the <span> tag like in the theme?

Upvotes: 1

Views: 178

Answers (2)

Mitch VanDuyn
Mitch VanDuyn

Reputation: 2878

link_to can optionally take a block. You can add all html_options in the html_options key. I believe (but am not positive) that you reference the class directly.

I just use html_options because it always works:

 <% link_to(link_to "My Stations", retailer_my_stations_path, html_options: {class: "drop-down-collapse"} ) do %>
     other tags i.e. span
 <% end %> 

Upvotes: 1

tirdadc
tirdadc

Reputation: 4713

You can pass a block to link_to:

<%= link_to retailer_my_stations_path, class: 'dropdown-collapse' do %>
  <i class='icon-edit'></i>
  <span>My Stations</span>
<% end %>

You can also create a helper method for this.

Upvotes: 4

Related Questions