2009-12-11 127 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