Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use link_to to link an image and a text

Well, I am using "font-awesome-rails" gem. I am pretty much used to font-awesome outside Rails, but I guess it's not that popular among Rails community.

Once installed, it creates icons using the format

<i class="nameoftheicon"> </i>

I thought of using it for my site logo, which would consist of the icon from font-awesome and some text. So I tried:

<%= link_to "", root_path, class: "icon-puzzle-piece icon-2x" %>
<%=  link_to "My site", root_path, id: 'logo'  %>

It works, but when I hover, they act as two different elements.

  1. What is the Rails way of combining an image and a text under a single <a> tag.

  2. And is there any popular Rails alternative to font-awesome?

like image 376
TradeRaider Avatar asked Jun 05 '13 18:06

TradeRaider


2 Answers

Pass a block to link_to and the block will be linked

<%= link_to path, id: "logo" do %>
  <i class="icon-puzzle-piece icon-2x"></i>
  My Super Site
<% end %>
like image 105
Jesse Wolgamott Avatar answered Sep 28 '22 09:09

Jesse Wolgamott


Try it,

You can directly mention rails image_tag in link_to as,

<%= link_to image_tag("image_name")+"your text", root_path, :class=>"icon-puzzle-piece icon-2x" %>
like image 23
bunty Avatar answered Sep 28 '22 08:09

bunty