rails 4 bootstrap 3 ajax modal

前端 未结 2 1919
礼貌的吻别
礼貌的吻别 2021-02-05 17:04

I\'m busy learning Rails 4 and I would like to display a bootstrap popup modal when a user clicks on a link, when the modal opens it needs to show the information relating to th

相关标签:
2条回答
  • 2021-02-05 17:52

    Have a try with another way. In this way, we are going to show the modal popup using explicit javascript command.

    In index.html.erb

    <%= link_to "view", work_path(w), remote: true, class: 'static-popup-link'%>
    
    <div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">Loading...</div>
    

    In application.js

    $(document).ready(function() {
    
      var clickOnPopupLink = function(){
        $('body').on('click', '.static-popup-link', function(){
          $('#myModal').modal('show');
        });
      }
    
      clickOnPopupLink();
    
    });
    

    In controller

    def show
      @work = Work.find(params[:id])
    end
    

    In show.js.erb

    $('#myModal').html("<%= j render("/works/modal")%>")
    
    0 讨论(0)
  • 2021-02-05 17:54

    You also need to show the modal, add $('#myModal').modal('show') in show.js.erb

    $("#myModal").html("<%= escape_javascript(render 'modal') %>");
    $('#myModal').modal('show')
    
    0 讨论(0)
提交回复
热议问题