Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
924 views
in Technique[技术] by (71.8m points)

ruby on rails - turbolinks issues with bootstrap modal

I doing a modal like this:

Link that shows the modal:

<%= link_to "vers?o resumida", resumed_rep_life_animal_path(animal, :partial => true), 'data-toggle' => 'modal', 'data-target' => '#myModal', 'data-no-turbolink' => true %>

Modal html itself:

<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-body"></div>
  <div class="modal-footer">
    <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Fechar</button>
  </div>
</div>

But, the data-no-turbolink dont work as expected. If I refresh the page, it works ok, but, when I browse the pages with turbolinks, looks like the data-no-turbolink is just ignored.

Am I doing something wrong? I have some modals like the example in my app, don't want to remove them and dont want to remove turbolinks neither...

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As davydotcom said, the reason the modals aren't working is because they are bound to $(document).ready instead of $(document).on('page:change'), which is what turbolinks uses.

The jquery-turbolinks gem will make it so that ready calls will also respond to turbolink's page:change calls.

Step 1: Add gem jquery-turbolinks to your Gemfile.

Step 2: Add it to your JavaScript manifest file, in this order:

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//
// ... your other scripts here ...
//
//= require turbolinks

Step 3: Restart your server. Boom!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...