Acrux
Acrux

Reputation: 406

Add data-toggle to image_tag

How does the syntax go if I want to do something like data-toggle="tooltip" title="Hooray!" but for my image_tag. I can't seem to figure out where I'm going wrong with my syntax.

My attempt:

<%= image_tag("/assets/info.svg",:class=>"infoicon"), :options => { :data => {toggle => "tooltip"},:title => "my caption"  %>

The error:

syntax error, unexpected ',', expecting ')'

I have the following js:

<script>
$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();   
});
</script>

Update: I tried using (since I missed an (}) in the image_tag above)

<%= image_tag("/assets/info.svg",:class=>"infoicon"), :options => { :data => {toggle => "tooltip"},:title => "my caption" } %>

but still the same error:

syntax error, unexpected ',', expecting ')'

Upvotes: 1

Views: 1338

Answers (1)

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33481

The image_tag is defined as:

image_tag(source, options = {})

So you could try using your class, data and title as the options argument of the image_tag helper, like:

<%= image_tag '/assets/info.svg', class: 'infoicon', data: { toggle: 'tooltip' }, title: 'my caption' %>

Upvotes: 3

Related Questions