Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Add Twitter Bootstap icons to Ruby on Rails "link_to()"

Im trying to add icons to a simple blog i have made to replace "show, edit & destroy"

can anyone shed some light on how to add bootstraps icons to a rails link_to()

cheers

4 Answers

The easiest way is to add the bootstrap classes to the link:

<%= link_to "linkname", link_destination_path, class: "btn btn-primary" %>

Here are all of the standard bootstrap options you have for buttons: http://twitter.github.io/bootstrap/base-css.html#buttons

... and the documentation for link_to: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

Hi Philipp Antar,

I can add classes to the link_to, however i would like to add one of the icons that bootstrap comes with, <i class="icon-search"></i>

any ideas? i shall have a look on the documentation link you gave

thanks

Darn it, I somehow read "buttons" instead of "icons". In that case, I would use a CSS :before pseudo class, read about it here. But it really depends on your needs. You could also set up some if...else statements with ERB-tags.

Hey Philipp Antar!

Try the image_tag in the link_to.

<%= link_to image_tag( path_to_image ), link_destination %>