Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Add HTML attribute without setting a value

I'm trying to create an image_tag and specify a data- attribute that does not have any value set to it. I'm trying to add data-tooltip, for use with Foundation 5 tooltips. It seems that if any value is actually set to this, Foundation uses the same tooltip text every time and ignores the title attribute of that element (so every tooltip will say whatever the first one you hovered on was... which seems buggy in and of itself on Foundation's part also)

This is what I need to generate:

<img src="[whatever]" title="My Tooltip" data-tooltip />

This will not work for me:

<img src="[whatever]" title="My Tooltip" data-tooltip="[insert anything here]" />

I have tried a number of different combinations, and read documentation, but it seems no matter what I put as the value, it ends up generating it like data-tooltip="null", or true, or false, or any string I pass.

image_tag(my_image, class: 'has-tip', title: "My Title Here", data: { tooltip: true })
like image 869
Ryan Avatar asked Dec 01 '13 03:12

Ryan


2 Answers

Try to pass in empty string as follows:

image_tag(my_image, class: 'has-tip', title: "My Title Here", data: { tooltip: "" })
like image 179
vee Avatar answered Oct 12 '22 00:10

vee


In Rails 4.1.4 using above tip :"data-tooltip" => '' renders data-tooltip without value.

like image 5
adass Avatar answered Oct 12 '22 02:10

adass