Rails link_to语法以添加一些内部html

时间:2012-08-29 22:07:35

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

我有这个代码通过'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”语法..谢谢!

1 个答案:

答案 0 :(得分:17)

您只需跳过第一个参数,可以将其余参数包装在parens中,然后添加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 %>