0

I'm having some trouble with a bootstrap modal in rails 4. I'm trying to display a modal when you click an image. And actually the modal is displayed, but only for a few seconds, and then it close itself. (I'm using bootstrap-sass gem)

This is the code I have:

<%= link_to image_tag (destacado.imagen.small), data: {toggle: "modal", target: "#myModal"} %>


            <!-- Modal -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
              <div class="modal-dialog" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Modal title</h4>
                  </div>
                  <div class="modal-body">
                    ...
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                  </div>
                </div>
              </div>
            </div>

Any idea what I am doing wrong?? Thank you in advance for any help! Peyu

Peyu
  • 401
  • 6
  • 15
  • You can take a look at this: http://stackoverflow.com/questions/15152486/how-to-add-bootstrap-modal-with-link-to-so-the-link-content-open-in-modal – Stephen C May 19 '17 at 18:06
  • I've already tryied that, and works fine for simple link, but it doesn't work for image clicking... – Peyu May 21 '17 at 19:55

1 Answers1

1

I think this is because your link_to will redirect the page.

Not a lot of information is provided, so that's just my guess.

If you wanted your link to just do data-toggle behaviour, maybe it doesn't need to be a link, just an image_tag with data-toggle behaviour.

fbelanger
  • 3,522
  • 1
  • 17
  • 32