Cor*_*mes 6 ruby-on-rails ruby-on-rails-4
现在我在导航栏中有这个链接.但是,一旦我把东西搬进Rails应用程序就没有用了.
<li><a href="products.html#ultra">Ultra</a></li>
Run Code Online (Sandbox Code Playgroud)
我知道它需要改为
<li><%= link_to "Ultra", product_path %></li>
Run Code Online (Sandbox Code Playgroud)
但我希望它直接转到我在产品页面上设置的Anchor.如何在Rails中完成?
url helper方法可以将anchor哈希作为参数,并将其作为锚链接输出:
<li><%= link_to "Ultra", product_path(anchor: 'ultra') %></li>
从文档:
link_to也可以产生带有锚点或查询字符串的链接:
link_to "Comment wall", profile_path(@profile, anchor: "wall")
# => <a href="/profiles/1#wall">Comment wall</a>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3475 次 |
| 最近记录: |