2

我试图让 link_to 能够创建带有选项和 html 选项的链接。我需要能够添加,所以我使用了 do 方法。

我的问题是:我如何让它与 :confirmation 一起使用。正如它所写的那样,它将确认附加到 url。我想将它作为 html 选项传入,这样它就会弹出对话框。

任何想法我需要做些什么才能让它表现得像那样?

<li>
  <%= link_to :controller => "services", :action => "delete_results", :build => @id, :suite => @cookie_value, :confirm => "Are you sure?" do %>
  <i class="icon-trash"></i>
    Delete Results
  <% end %>
</li>

谢谢

4

1 回答 1

3

url_options 和 html_options 是 link_to 的独立属性。您需要告诉 ruby​​ 它们是列表中的不同参数

link_to({:controller => "services", :action => "delete_results", :build => @id, :suite => @cookie_value}, {:confirm => "Are you sure?"})

在 {} 中包装第二个哈希是可选的,但可以简化阅读

于 2012-09-20T18:06:50.053 回答