Ruby on Rails link_to内部id

时间:2009-12-11 15:50:51

标签: ruby-on-rails ruby link-to

如何使用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

1 个答案:

答案 0 :(得分:26)

link_to 可以为网址添加锚点。

来自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" } %>