RoR - 将参数传递给 Bootstrap modal。背景不会淡出



我显示配置文件列表,需要通过模式显示有关每个用户的更多详细信息:

<%= link_to profile.full_name, { :action => :profile_modal, 
                                :profile_id_param => profile.id }, 
                              {remote: true, 'data-toggle' => 'modal', 
                                'data-target' => '#modal-window'} %> 

这是模态的容器 fiv:

<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="tue">
</div> 

控制器操作:

  def profile_modal
    @profile = Profile.find_by_id(params[:profile_id_param])
    respond_to do |format|
      format.js  
      # format.html
    end 
  end 

和profile_modal.js.erb:

$("#modal-window").html("<%= escape_javascript(render partial: 'shared/profile_modal', locals: { profile: @profile }) %>");
$("#profile_modal").modal();

模 态:

<div class="modal fade" id="profile_modal" tabindex="-1" role="dialog" aria-labelledby="msgModal" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title"> 
          <% if @profile %> <%= @profile.id %> <% end %> 

上面的这段代码根据params[:profile_id_param]值传递变量,但存在两个问题:

  1. 打开模态并关闭它后,背景不会再次淡入。它仍然更暗,只是模态本身消失了;
  2. 出于某种原因,我无法将当地人传递给模态。如您所见,我在其中使用了实例变量,因为它错误地将我定义为未定义。

这是怎么回事?

更新:

Treid 在单击时关闭像这样的涡轮链接:

<%= link_to profile.full_name, { :action => :profile_modal, 
                                  :profile_id_param => profile.id }, 
                                {remote: true,  'data-turbolinks' => false, 'data-toggle' => 'modal', 
                                    'data-target' => '#modal-window'} %>

但没有帮助

解决此问题的一种方法:

$('#modal-window').on('hide.bs.modal', function () {
  $('#modal-window').css("display", "none");
})
$('#modal-window').on('show.bs.modal', function () {
  $('#modal-window').css("display", "block");
})
$("#modal-window").html("<%= escape_javascript(render partial: 'shared/profile_modal', locals: { profile: @profile }) %>");
$("#profile_modal").modal();

并禁用backdrop

<%= link_to profile.full_name, { :action => :profile_modal, 
                                 :profile_id_param => profile.id }, 
                               { remote: true, 'data-toggle' => 'modal', 
                                'data-target' => '#modal-window', 
                                'data-backdrop' => "false"} %> 

还注意到,即使在模态关闭后,#modal-window也会获得 z-index 1050,但是:

$('#modal-window').on('hide.bs.modal', function () {
  $('#modal-window').css("display", "0");

没有修复它。

我为以下方面保持此问题开放:

a) 解决此问题的更好方法

b) 如何将当地人传到这种模式?

最新更新