ruby-on-rails - Ruby on Rails link_to 内部 ID

标签 ruby-on-rails ruby link-to

我如何使用 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

最佳答案

link_to 可以将 anchor 添加到 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" } %>

关于ruby-on-rails - Ruby on Rails link_to 内部 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1888960/

相关文章:

ruby - Ruby 中的 Zlib 解压 .gz

ruby-on-rails - 如何从hidden_​​field_tag通过link_to参数传递值(Rails)

css - 如何使用 Assets 管道更改 Rails 4 中的 link_to 悬停图像

ruby-on-rails - postgreSql 和 Rails 命令

ruby - Capybara webkit 无法连接到 127.0.0.1 上的端口 0

ruby-on-rails - Rails 数据库添加列

ruby-on-rails - 为什么我的 Rails Controller 测试没有路由?

ruby-on-rails - 如何从Rails Controller 中混合并调用link_to?

ruby-on-rails - 如何监听由 3rd 方应用程序触发的数据库更改

ruby-on-rails - factory_girl transient 属性的未定义方法