cyonder
cyonder

Reputation: 872

link_to doesn't work, controller appears as a html attribute

I have been googling last 2 hours and unfortunately I cannot fix this, though I thought it must be easy.

<%= link_to 'Log Out', {:controller => 'static_pages', :action => 'index'} do %>
  <i class="glyphicon glyphicon-log-out link-icon"></i>
<% end %>

This the code I have. So, I need "Log Out" link to appear with log-out icon, which is from bootstrap. But HTML output of this code is this:

<a controller="static_pages" action="index" href="Log Out">
  <i class="glyphicon glyphicon-log-out link-icon"></i>
</a>

I tried many ways to fix this, but I also tried removing "do" so, I can see if it causes the problem. This is the link after I removed "do":

<%= link_to 'Log Out', {:controller => 'static_pages', :action => 'index'} %>

HTML output of this is:

<a href="/">Log Out</a>

It doesn't make sense. Because I have same link_to in my footer and it works. Footer:

<%= link_to 'Log In', {:controller => 'users', :action => 'login'} %>

Footer output:

<a href="/users/login">Log In</a>

So, why this isn't working in another page? Thank you.

Upvotes: 0

Views: 695

Answers (1)

Alexander Shlenchack
Alexander Shlenchack

Reputation: 3869

When you pass a block to the link_to helper this will be a body for it.

<%= link_to :controller => 'static_pages', :action => 'index' do %>
  <i class="glyphicon glyphicon-log-out link-icon"></i>
  Log Out
<% end %>

Upvotes: 1

Related Questions