Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为什么确认rails按钮的选项不起作用_Ruby On Rails - Fatal编程技术网

Ruby on rails 为什么确认rails按钮的选项不起作用

Ruby on rails 为什么确认rails按钮的选项不起作用,ruby-on-rails,Ruby On Rails,我有一个轨道按钮,我希望它在继续之前显示一个确认对话框 <%= button_to("Rebuild indexes", action: "rebuild_indexes", data: {confirm: "Are you sure you want to reset the indexes?" }) %> 如果我检查一下按钮,我就明白了 <form class="button_to" method="post" action="/help/rebuild_indexes?

我有一个轨道按钮,我希望它在继续之前显示一个确认对话框

<%= button_to("Rebuild indexes", action: "rebuild_indexes", data:
{confirm: "Are you sure you want to reset the indexes?" }) %>
如果我检查一下按钮,我就明白了

<form class="button_to" method="post" action="/help/rebuild_indexes?data%5Bconfirm%5D=Are+you+sure+you+want+to+reset+the+indexes%3F">
  <input type="submit" value="Rebuild indexes">
  <input type="hidden" name="authenticity_token" value="3mnAMmyHaINiDngjQn87EMmhmetp2VJcX+lwcmbUlhwBfv7V1hpLc9ZY1OF5JAFm9erFJjX+qyDz35/KK41jaA==">
</form>


在显示确认框时,我遗漏了什么

尝试将链接添加到,而不是按钮添加到。”/“索引/重建”是路由

<%= link_to "Rebuild indexes", '/indexes/rebuild', data: { confirm: 'Are you sure you want to reset the indexes?' }, class:"btn btn-default" %>

数据:{confirm:}
被附加到url参数哈希上,而不是作为第三个参数传递-尝试像这样分离哈希:

button_to("Rebuild indexes", {action: "rebuild_indexes"}, data: {confirm: "Are you sure you want to reset the indexes?" })

这产生

<form class="button_to" method="post" action="/home/delete?cardId=15">
 <button data-confirm="Are you sure you want to delete?" type="submit">
    <i class="fa fa-times"></i>
 </button>
</form>

我在以下行中遇到了类似的问题:

 <%= button_tag 'Delete', onclick: "location.href = #{polymorphic_url(obj)}", :method => :delete, type: 'button', class: 'btn btn-danger', title: 'Delete', id: 'delete_btn', data: { confirm: 'Are you sure you want to delete this record?' } %>
:删除,键入:'button',class:'btn btn danger',title:'delete',id:'delete_btn',数据:{confirm:'确实要删除此记录吗?'}%>

删除“类型:'按钮'”修复了确认提示问题

这是turbolink功能的已知问题。您需要通过在数据属性中插入“turbolinks:false”,显式关闭帮助器方法的turbolink:

<%= button_to("Rebuild indexes", action: "rebuild_indexes", data:
{turbolinks: false, confirm: "Are you sure you want to reset the indexes?" }) %>


您是否尝试将操作放入哈希中?服务器日志中有什么内容吗?浏览器日志(通常在控制台选项卡中)如何?@ruby\u newbie-哈希工作得非常好
按钮\u to
也支持这一点。看见
 <%= button_tag 'Delete', onclick: "location.href = #{polymorphic_url(obj)}", :method => :delete, type: 'button', class: 'btn btn-danger', title: 'Delete', id: 'delete_btn', data: { confirm: 'Are you sure you want to delete this record?' } %>
<%= button_to("Rebuild indexes", action: "rebuild_indexes", data:
{turbolinks: false, confirm: "Are you sure you want to reset the indexes?" }) %>