现在我的肚脐上有这个链接。但是,一旦我把东西转移到Rails应用程序中,就无法工作了。
<li><a href="products.html#ultra">Ultra</a></li>我知道它需要改为
<li><%= link_to "Ultra", product_path %></li>但是,我想让它直接到我在产品页面上设置的Anchor。这是如何在Rails中实现的?
发布于 2016-01-26 02:37:16
url助手方法可以将anchor哈希作为参数,并将其作为锚链接输出:
<li><%= link_to "Ultra", product_path(anchor: 'ultra') %></li>
来自医生们
link_to还可以生成具有锚点或查询字符串的链接:
link_to "Comment wall", profile_path(@profile, anchor: "wall")
# => <a href="/profiles/1#wall">Comment wall</a>https://stackoverflow.com/questions/35006147
复制相似问题