jba*_*sta 1 html ruby-on-rails ruby-on-rails-3
我正在尝试创建指向特定页面部分ID的链接。
就像波纹管的html,但我想改用rails ...
<a id="tips">Useful Tips Section</a>
<a href="#tips">Visit the Useful Tips Section</a>
Run Code Online (Sandbox Code Playgroud)
如何在link_to函数中指定“ #tips”?还是应该创建一个特定的路线?怎么样?
提前致谢
您可以使用
<%= link_to "Visit the Useful Tips Section", action_path(anchor: tips) %>
在路线中,您可以指定action_path。
根据Rails API文档,您应该采用上述方式,请参考this,并找到以下示例:
link_to "Comment wall", profile_path(@profile, anchor: "wall")
# => <a href="/profiles/1#wall">Comment wall</a>
Run Code Online (Sandbox Code Playgroud)