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.
What is the Rails way of combining an image and a text under a single
<a>
tag.And is there any popular Rails alternative to font-awesome?
Try it,
You can directly mention rails image_tag in link_to as,
Pass a block to
link_to
and the block will be linkedYes, you are using a vector font as image but you can use image_tag too, for example:
Don't forget link together both of them with "+"
Yes you can. For complex anchor such as images, just remove the first argument(the link text or anchor), and attach a block after the method.
The content inside block will become the anchor.
Hey guys this is a good way of link w/ image (it has lot of props in case you want to css attribute for example replace "alt" or "title" etc)
Hope this helps!