rails 4 bootstrap 3 ajax modal

前端 未结 2 1933
礼貌的吻别
礼貌的吻别 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'%>
    
    
    

    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")%>")
    

提交回复
热议问题