Rails中link_to语法用于添加一些内部HTML

9
我有这段代码,通过“link_to”函数生成“取消关注”按钮:
<%= link_to "Non seguire più", user_user_relationship_path(id:@relationship.id), remote: true, id: "follow_#{@user.id}", class:"btn btn-small btn-danger", method: :delete %>

我想知道如何使用带有所有参数的"do..end"语法。谢谢!


你想要实现什么目标?为什么你想要把一个块放在那里? - varatis
我想添加一个图标,就像在Bootstrap的文档中所示。 - Ciampo
1个回答

20

你可以跳过第一个参数,把剩下的内容用括号包起来,然后加上 do/end。

<%= link_to(user_user_relationship_path(id:@relationship.id), remote: true, id: "follow_#{@user.id}", class:"btn btn-small btn-danger", method: :delete) do %>
  <!-- your button html here -->
<% end %>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接