Joe Essey
Joe Essey

Reputation: 3527

How to apply bootstrap modal call to an image tag?

I've got an image display page. I want to add a modal with a larger version of the image. I have created a button according to the bootstrap instructions that does the job:

<button type="button" data-toggle="modal" data-target="#myModal">View</button>

I'm trying to apply the data-toggle and data-target portions of that code to my image_tag but I can't figure out how. Here's my best guess:

 <%= image_tag(@illustration.image.url),  :options => { :data-toggle => "modal", :data-target => myModal}  %> 

Thanks for any suggestions.

Upvotes: 0

Views: 2677

Answers (1)

MurifoX
MurifoX

Reputation: 15089

The syntax of your data attributes hash is wrong, you can do it two ways:

<%= image_tag(@illustration.image.url),  :options => { "data-toggle" => "modal", "data-target" => myModal}  %>  

Or

<%= image_tag(@illustration.image.url),  :options => { :data => {toggle => "modal"}, :data => {target => myModal}}  %> 

UPDATE:

See this for the link_to with image_tag inside: link_to image_tag with inner text or html in rails

Upvotes: 2

Related Questions