链接到Rails App页面上的Anchor

时间:2016-01-26 02:33:15

标签: ruby-on-rails ruby-on-rails-4

现在我的导航栏中有这个链接。但是,一旦我将事情转移到Rails应用程序中,就无法使用。

<li><a href="products.html#ultra">Ultra</a></li>

我知道需要将其更改为

<li><%= link_to "Ultra", product_path %></li>

我希望它直接转到我在产品页面上设置的主播。如何在Rails中完成?

1 个答案:

答案 0 :(得分:4)

url helper方法可以将anchor哈希作为参数,并将其作为锚链接输出:

<li><%= link_to "Ultra", product_path(anchor: 'ultra') %></li>

来自the docs

  

link_to还可以生成包含锚点或查询字符串的链接:

link_to "Comment wall", profile_path(@profile, anchor: "wall")
# => <a href="/profiles/1#wall">Comment wall</a>
相关问题