6

使用できるページの「whatever_id」に移動したい場合、通常、ページの特定の (html) ID に移動するために link_to を使用するにはどうすればよいですか

<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"%> 

ヘルパー メソッド。誰もこれを行う方法を知っていますか? 出来ますか?

レール 2.3.4

4

1 に答える 1

27

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" } %>
于 2009-12-11T16:19:17.783 に答える