2009-12-11 208 views
6

我如何使用的link_to序去一个特定的(HTML)的ID在页面上通常 ,如果我想进入“whatever_id”页面上,我可以使用Ruby on Rails的的link_to内部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

回答

26

的link_to可以添加锚点到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" } %> 
+0

谢谢,工作就像一个魅力! – Schneems 2009-12-11 19:25:48