Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add an icon to a button_tag using HAML?

I am having trouble trying to make a play button using HAML.

 =button_tag clue_path(@question), class: "btn btn-lg glyphicon glyphicon-play" 

Results in html

<button><icon class:"glyphicon glyphicon-play">/question/1/clue</i></button>

It should be

<button><icon class: "glyphicon glyphicon-play"></i></button>

I'm super close to resolving it. What am I missing?

like image 374
Michael Stokes Avatar asked Jan 07 '23 13:01

Michael Stokes


2 Answers

If you're looking to put an icon inside a button with Bootstrap and HAML, try:

%button.btn.btn-lg.btn-default
  %i.glyphicon.glyphicon-play
like image 193
ahmacleod Avatar answered Jan 17 '23 21:01

ahmacleod


a button tag doenst have a href attribute.

you use a-tags style them like a button.

also i recommend you to use "fontawesome" instead of glyphicon. the integration is super easy, just add the gem and tell bootstrap to use FA.

list of icons is here: https://fortawesome.github.io/Font-Awesome/icons/

for the button do this

=link_to clue_path(@question), class: "btn btn-lg" do 
  %i.glyphicon.glyphicon-play

if you are using the font-awesome gem then its just

=link_to clue_path(@question), class: "btn btn-lg" do 
  =icon "glyphicon-play"

or

=link_to icon("glyphicon-play"), clue_path(@question), class: "btn btn-lg"
like image 27
Tim Kretschmer Avatar answered Jan 17 '23 22:01

Tim Kretschmer