6

如果我想访问我可以使用的页面上的“whatever_id”,我如何使用 link_to 才能正常访问页面上的特定(html)ID

<a href="http://www.example.com/index/mypage#whatever_id>Click Here</a>

但我想使用我的 link_to

<%= link_to "click here" , {:action => "mypage", :controller => "index" }, :id => "#whatever_id"%> 

辅助方法。有谁知道如何做到这一点?是否可以?

导轨 2.3.4

4

1 回答 1

27

link_to可以将锚点添加到 URL。

文档中,

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

在你的情况下,你可能想要,

 <%= link_to "click here" , {:action => "index", :controller => "mypage", :anchor => "whatever" } %>
于 2009-12-11T16:19:17.783 回答