【问题标题】:Delete confirmation rails删除确认栏
【发布时间】:2016-04-01 03:16:53
【问题描述】:

我在预定消息上有一个删除选项,我只是想要一个用户想要删除的快速弹出验证(你确定吗?)。完成此任务的最简单方法是什么?

这是截图和一些代码。

<div class="container">
<h2>Listing Scheduled Messages</h2>
<table class="table table-striped">
<thead>
  <tr>
    <th><%= sortable 'body', 'Messages' %></th>
    <th><%= sortable 'send_at', 'Sent Time' %></th>
  </tr>
</thead>
  <tbody>
    <% @message.each do |message| %>
    <tr>
      <td><%= message.body %></td>
      <td>Send out in: <%= time_ago_in_words message.send_at %></td>
      <td><%= link_to 'Edit', edit_message_path(message) %></td>
      <td><%= link_to 'Delete', message_path(message),method: :delete, :confirm=>'Are you sure?' %></td>
      <% end %>
    </tr>
    </tbody>
    </table>
    <p><%= link_to "Send Message", root_path %></p>
    </div>

【问题讨论】:

  • 什么不起作用?当您单击删除时,您没有得到确认吗?
  • 你试试这个吗? data: { confirm: "Are you sure?" }

标签: ruby-on-rails ruby


【解决方案1】:

如果您使用 Rails 4syntax has changed,因此 confirm 属性现在在 data 哈希中处理。

之前: confirm: "Are you sure?"

之后: data: { confirm: "Are you sure?" }

试试这个:

&lt;%= link_to 'Delete', message_path(message),method: :delete, data: {confirm: 'Are you sure?' }%&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 2011-10-06
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多