如何在rails上的ruby中使用带有link_to的模态

时间:2017-07-28 13:29:24

标签: html ruby-on-rails ruby

我正在尝试link_to按钮操作

 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newTag">
          <i class="fa fa-plus"></i> New Tag
        </button>

我想将其作为path:传递给此代码:

<%= render "shared/empty_view", path: contacts_path, title: "You do not have any tags!", action:"Create Tag", image: "/no_products.png" %>

我尝试过针对类似问题的类似答案,但我似乎无法获得正确的语法。

1 个答案:

答案 0 :(得分:4)

<%= link_to "#newTag", data: { toggle: "modal" } do %>
  <i class="fa fa-plus"></i> New Tag
<% end %>

<div id="newTag" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>