ruby-on-rails - Rails link_to 语法以添加一些内部 html

标签 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”语法。谢谢!

最佳答案

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

关于ruby-on-rails - Rails link_to 语法以添加一些内部 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12187197/

相关文章:

ruby-on-rails - Ruby on Rails - link_to - 类引述

mysql - ActiveRecord 从类中选择一个属性

ruby - 为什么 3.times 需要一个 .each 如果作为参数传递,而不是直接使用,如 "3.times do xyz end"

ruby - 如何使用 Nix 而不是 Homebrew 在 OS X 上设置 Ruby?

ruby-on-rails - Ruby on Rails 的最后 20%

ruby-on-rails - 在 rails 中使用 link_to 提交表单

ruby-on-rails - 为什么我的 rake db :migrate throws error message?

ruby-on-rails - 每当 gem : I set :output but the logfile doesn't show up where I'd expect it to

javascript - 在 Rails 4 中将数组(Javascript)放入 PostgreSQL

ruby-on-rails - Rails 2 到 Rails 3 : using link_to instead of link_to_remote (including remote and update)