我要如何使用的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 可以锚添加到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" } %>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top