2009-12-11 4 views
6

Comment puis-je utiliser un link_to envue d'aller à un spécifique (html) ID sur une page normalement si je voulais aller à la « whatever_id » sur une page que je pourrais utiliserRuby on Rails link_to id interne

<a href="http://www.example.com/index/mypage#whatever_id>Click Here</a> 

mais je voudrais utiliser mon link_to

<%= link_to "click here" , {:action => "mypage", :controller => "index" }, :id => "#whatever_id"%> 

méthodes d'aide. Est-ce que quelqu'un sait comment faire ça? C'est possible?

Rails 2.3.4

Répondre

26

link_to peuvent ajouter des points d'ancrage à une URL.

De l'documentation,

link_to "Comment wall", profile_path(@profile, :anchor => "wall") 
# => <a href="/profiles/1#wall">Comment wall</a> 

Dans votre cas, vous voulez probablement,

<%= link_to "click here" , {:action => "index", :controller => "mypage", :anchor => "whatever" } %> 
+0

Merci, a travaillé comme un charme !! – Schneems