添加一个 class 到 link_to 带有锚点的块

Adding a class to link_to block with anchor

我正在尝试使用 link_to helper'anchor' tag 环绕在 svg image 周围。 link 的 href 是同一页面上的锚点,它必须有一个 class。我按照文档的说明进行操作,没有 class 也能正常工作。但是当我添加 class 时,它会添加到 href (a href="/?class=test#section-1")。我需要它呈现如下:<a href="/section-1" class="logo-inclub">.

这是我正在关注的文档:

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


这是我的代码(我使用 slim 作为模板):

= link_to(anchor: 'section-1' , class: 'logo-inclub')  do
   = svg_image("logo_inclub")       

如有任何帮助,我们将不胜感激。谢谢!!

你是不是忘记了url?

= link_to("http://whosebug.com", anchor: 'section-1', class: 'logo-inclub')  do
   = svg_image("logo_inclub")   

您的问题可能会自行回答:

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

所以你的 link 应该是:

= link_to('/section-1' , class: 'logo-inclub' )  do
   = svg_image("logo_inclub")