gpt4 book ai didi

html - 在 rails 中创建 html anchor

转载 作者:行者123 更新时间:2023-11-28 04:58:14 25 4
gpt4 key购买 nike

我正在尝试创建指向特定页面部分 ID 的链接。

它类似于下面的 html,但我想改用 rails...

<a id="tips">Useful Tips Section</a>

<a href="#tips">Visit the Useful Tips Section</a>

如何在 link_to 函数中指定“#tips”?或者我应该创建一个特定的路线?怎么办?

提前致谢

最佳答案

你可以使用

<%= link_to "Visit the Useful Tips Section", action_path(anchor: tips) %>

在 route 你可以指定action_path .

根据 Rails API 文档,您应该按照上述方式进行操作,请参阅 this , 并找到以下示例:

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

关于html - 在 rails 中创建 html anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19478945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com