我如何使用 link_to 才能正常转到页面上的特定 (html) ID 如果我想转到我可以使用的页面上的“whatever_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"%>
辅助方法。有谁知道如何做到这一点?可能吗?
rails 2.3.4
最佳答案
link_to 可以将 anchor 添加到 URL。
来自documentation ,
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" } %>
关于ruby-on-rails - Ruby on Rails link_to 内部 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1888960/