【问题标题】:Rails 4 - link_to with confirm in RailsRails 4 - 在 Rails 中确认的 link_to
【发布时间】:2015-07-14 11:28:44
【问题描述】:

我正在尝试自定义我的对话框,确认 rails 4 中的 link_to。但我不明白他为什么将 html 称为“确认”,而应该是“数据确认”!

我尝试了很多方法,总是生成“确认”,像这样:

<%= link_to 'Delete', user, :method => :delete, :confirm => 'Are you sure?' %>

<a confirm="Are you sure?" rel="nofollow" data-method="delete" href="/user/13">Delete</a>

我遵循了这个教程: http://thelazylog.com/custom-dialog-for-data-confirm-in-rails/ 我在教程中使用了示例,但也不起作用

【问题讨论】:

    标签: ruby-on-rails-4 link-to


    【解决方案1】:

    确认已在 Rails 4 中被弃用。

    所以使用新语法:

    <%= link_to "title", "#", data: {confirm: "Are you sure!"} %>
    

    【讨论】:

      【解决方案2】:

      要在 rails 7 中获得相同的行为,您应该改用 turbo_confirm 键:

      <%= link_to 'Delete', user,
        data: {turbo_method: :delete, turbo_confirm: 'Are you sure?'} %>
      

      【讨论】:

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