troubleshooting icons in link_to
-
20-12-2019 - |
Question
Alright guys, this one seems like a slowball, but I'm stumped here. I'm currently using rails 4.1.1 and trying to get a link_to to appear as a button with an icon instead of text.
erb:
<%= link_to messages_path, do %>
<i class="btn btn-primary glyphicon glyphicon-envelope"></i>
<% end %>
Basically I grabbed the above code from here, but it gives me this error when I try to use it:
/Users/user/project/app/views/pages/home.html.erb:20: syntax error, unexpected keyword_do_block ...end= link_to messages_path, do @output_buffer.safe_append=' ... ^ /Users/user/project/app/views/pages/home.html.erb:29: syntax error, unexpected keyword_ensure, expecting end-of-input
Solution
depending on which bootstrap version you have try one of these:
<%= link_to messages_path, class: 'btn btn-primary' do %>
<span class="glyphicon glyphicon-envelope"></span>
<% end %>
or
<%= link_to messages_path, class: 'btn btn-primary' do %>
<i class="glyphicon glyphicon-envelope"></i>
<% end %>
Basically the btn class belongs on your link and the glyphicon is probably a span now.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow