如何使用 link_to 添加引导模式,以便链接内容在模式中打开?

2024-03-15

我正在尝试使用引导模式http://twitter.github.com/bootstrap/javascript.html#modals http://twitter.github.com/bootstrap/javascript.html#modals在 Rails 链接上以在模式中打开该链接

<%= link_to page_path, target: '_blank' %>

但不知何故它不起作用。标准切换代码是 -

<a data-toggle="modal" href="#myModal" class="btn">Launch demo modal</a>

但我不知道如何将它应用到 Rails 中的 link_to ,有什么帮助吗?

Thanks


如果您想在隐藏状态下的页面上预加载模式,下面是代码

<%= link_to "Open modal", "#my-modal", :class => "btn", "data-toggle" => "modal" %>
<div class="modal hide fade" id="my-modal" title="My modal">
  <div class="modal-header">
    <button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    Modal Body
  </div>
  <div class="modal-footer">
    <button aria-hidden="true" class="btn" data-dismiss="modal">Close</button>
  </div>
</div>

如果你想通过ajax加载模态,那么你可以这样做

<%= link_to "Open modal", new_post_path, :class => "btn", :remote => true, "data-toggle" => "modal", "data-target" => "my-modal" %>
<div class="modal hide fade" id="my-modal" title="My modal">
  <div class="modal-header">
    <button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
    <h3 id="myModalLabel">New Post</h3>
  </div>
  <div class="modal-body a-unique-class">
    New Post Body
  </div>
  <div class="modal-footer">
    <button aria-hidden="true" class="btn" data-dismiss="modal">Close</button>
  </div>
</div>

In posts/new.js.erb你会包括

$(".a-unique-class").html('<%= j render "posts/_form" %>')

确保您有一个unique每个模态体的 id 或 class。

假设您想使用模态形式创建一个新帖子,控制器代码和_form.html.erb已就位

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 link_to 添加引导模式,以便链接内容在模式中打开? 的相关文章

随机推荐