是否可以在第一次加载时让根页面滚动到 anchor 链接?
在我的 routes.rb 文件中,我做了
root :to => 'home#index#header' (#header being the anchor element in the index.html.erb)
但是,显然,这没有用。
最佳答案
您可以在您的 Controller 中通过将 :anchor
参数传递给任何 URL 帮助程序来完成此操作。参见 How do you use anchors for IDs in routes in Rails 3?一个很好的例子。
您也可以直接在 View 中通过 javascript 执行此操作(它属于 IMO)。
所以不,我不知道如何在您的 routes.rb
中做到这一点,但即使我知道,我也会建议不要这样做。在您的 route ,您将传入请求连接到 Controller 和操作。 HTML anchor 是与 View 相关的东西,因此它不属于 routes.rb
。
关于ruby-on-rails - Rails - routes.rb - 滚动到根页面的 anchor 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23652269/