Reputation: 37
i want to show an small icon instead of a textlink. using this piece of code:
<li>
<%= link_to '', :class => 'nav-icon' do %>
<span class="icon-home">Home</span><%= root_path %>
<% end %>
</li>
but rails now shows me the icon followed by a / is there any way to avoid that behavior?
Upvotes: 0
Views: 1227
Reputation: 824
<li>
<%= link_to root_path, :class => 'nav-icon' do %>
<span class="icon-home">Home</span>
<% end %>
</li>
The /
displayed after your icon is generated by <%= root_path %>
.
<%= %>
seems:
please ruby, write this on my html.
so ruby wrote your root_path
variable, and your root_path
is equal to /
.
remove your <%= root_path %>
after <span class="icon-home">Home</span>
and everything will be ok.
Upvotes: 2
Reputation: 3895
Following should work
<li>
<%= link_to '', :class => 'nav-icon' do %>
<span class="icon-home">Home</span>
<% end %>
</li>
Reason: the /
is coming due to this code <%= root_path %>
and writing just <%= link_to '', :class => 'nav-icon' do %>
will create link with empty href
I think you should give your path in the first argument of link_to
as follows
link_to(url, html_options = {}) do
# your icon code
end
Upvotes: 2