Ruby on Rails link_to internal id

邮差的信 提交于 2019-12-07 03:27:08

问题


How do i use a link_to inorder to go to a specific (html) ID on a page normally if i wanted to go to the "whatever_id" on a page i could use

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

but i would like to use my link_to

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

helper methods. Does anyone know how to do this? Is it possible?

Rails 2.3.4


回答1:


link_to can add anchors to a URL.

From the documentation,

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

In your case you probably want,

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


来源:https://stackoverflow.com/questions/1888960/ruby-on-rails-link-to-internal-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!