【问题标题】:link_to confirm not working with controller/actionlink_to 确认不使用控制器/动作
【发布时间】:2017-03-28 18:18:40
【问题描述】:

更新 - 我刚刚检查过,但都没有确认有效。

我需要对 link_to 进行确认。我已经尝试了 data/confirm 属性的几种变体,但它绕过了确认对话框。

我的链接是

 <%= link_to 'new bs line', 
   :controller => :bedsheet_lines, 
   :action => :create_new_bedsheet_line,  
   :data => {:confirm => 'Are you sure that you want to export the Bedsheets?'} %> <br>

这行不通,但是常规的 link_to 可以: 而且这也行不通

  <%= link_to "Export Data as a CSV file ", 
      slitter_bedsheet_export_path(format: "csv"), 
      :data => {:confirm => 'Are you sure that you want to export the Bedsheets?'} %> <br>

如果我进行检查,则不会显示确认的链接看起来像

  <a href="/bedsheet_lines/new_bedsheet_line?
   data%5Bconfirm%5D=Are+you+sure+that+you+want+to+export+the+Bedsheets%3F">
  new bs line</a> <br>

虽然显示确认的链接看起来像 ,但这项工作也不会消失。

  <a data-confirm="Are you sure that you want to export the Bedsheets?" 
   href="/csv_export.csv">Export Data as a CSV file </a> <br>

我的怀疑是,当您的 link_to 指定操作和控制器时,确认将不起作用。如果这是真的,我应该能够找到解决这个问题的方法。现在我不确定我的问题出在哪里。

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    不知道为什么哈希语法很重要,但我使用

    <%= link_to 'text', path(param), data: { confirm: 'confirmation' } %>
    

    编辑:

    指定控制器和动作:

    <%= link_to 'text', { controller: 'bedsheet_lines', action: 'create_new_bedsheet_line' }, data: { confirm: 'confirmation' } %>
    

    【讨论】:

    • 我缺少包含控制器/动作的括号。另外,我在stackoverflow.com/questions/16668949/… 找到了提示
    • 显然,当我升级我的 Jquery 库时,我已经从 application.js 中删除了//= require jquery_ujs(不确定当时我为什么这样做)。我把那行放回去,做出你建议的改变,预编译,重新启动服务器,确认现在正在工作
    猜你喜欢
    • 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
    相关资源
    最近更新 更多