【问题标题】:rendering twitter bootstrap modal in rails upon redirect重定向时在 Rails 中呈现 twitter 引导模式
【发布时间】:2012-11-07 06:15:52
【问题描述】:

我有一个可以从我的视图中的某个页面点击的有效模式链接:

<a href="#" data-toggle="modal" data-target="#manifesto-modal">Manifesto &amp; Rules</a>

除了可以在此页面上单击之外,我还希望它在重定向到此页面时默认显示。我还没有找到一个很好的方法来从控制器或其他地方对此进行编码,但无法想象它需要太多。感谢您的输入!

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap modal-dialog


    【解决方案1】:

    根据文档,您可以使用 the flash(未经测试):

    redirect_to your_path, flash: { manifesto_modal: true }
    

    那么在你看来:

    <% if flash[:manifesto_modal] %>
      // a script to display modal on document ready
    <% end %>
    

    【讨论】:

    • 这样? $(document).ready(function(){ $("#manifesto_modal").dialog({modal: true}); });
    • 我找到了这个链接,但没有成功:stackoverflow.com/questions/11285600/…
    • 好的,我发现如果我添加这个: $('#manifesto-modal').modal('show');在我的 Rails 资产管道的主“users.js”文件中,模态会在我的“edit_profile”页面上自动弹出,如我所愿。不幸的是,它现在在每个页面上都会自动打开。我如何将此 javascript 限制到某个页面?在视图 html.erb 中嵌入脚本不起作用:
    • 记得使用 并且仅当您被重定向时才包含您的脚本
    【解决方案2】:

    我用这个 JavaScript 解决了这个问题。这可能不是最好的方法,我很想听听人们对此的看法:

      if ( window.location.pathname == "/edit_profile" ) {
        $('#manifesto-modal').modal('show');
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多