代码之家  ›  专栏  ›  技术社区  ›  Schneems

Ruby on Rails链接到内部ID

  •  5
  • Schneems  · 技术社区  · 16 年前

    如何使用链接?以便正常转到页面上的特定(HTML)ID 如果我想转到我可以使用的页面上的“随便什么ID”

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

    但是我想用我的链接

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

    帮助程序方法。有人知道怎么做吗?有可能吗?

    Rails 2.3.4

    1 回复  |  直到 11 年前
        1
  •  25
  •   Michiel Kalkman Sanath    16 年前

    林克托 可以向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" } %>
    
    推荐文章