【问题标题】:Ruby on Rails link_to internal idRuby on Rails link_to 内部 id
【发布时间】:2009-12-11 15:50:50
【问题描述】:

我如何使用 link_to 才能正常转到页面上的特定 (html) ID 如果我想转到页面上的“whatever_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

【问题讨论】:

    标签: ruby-on-rails ruby link-to


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      相关资源
      最近更新 更多