• 我正好遇到这个问题,一开始看了代码里的注释没搞懂,最后看了楼上发的文档才弄懂。

    代码的注释是这样的:

    # You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
         #
         #   <%= link_to(@profile) do %>
         #     <strong><%= @profile.name %></strong> -- <span>Check it out!</span>
         #   <% end %>
         #   # => <a href="/profiles/1">
         #          <strong>David</strong> -- <span>Check it out!</span>
         #        </a>
    

    这个链接里的文档 我根据文档里的这个

    link_to(url, html_options = {}) do
      # name
    end
    

    举个例子:

    <%= link_to logout_path, method: :delete, class: 'dropdown-item' do %>
      <i class="fa fa-sign-out" aria-hidden="true"></i>
      Log out
    <% end %>
    

    最后生成

    <a class="dropdown-item" rel="nofollow" data-method="delete" href="/logout">
      <i class="fa fa-sign-out" aria-hidden="true"></i>
      Log out
    </a>