Right now I have this link in my navbar. But once I moved things into a Rails app is has not worked.
<li><a href="products.html#ultra">Ultra</a></li>
I understand it needs to be changed to
<li><%= link_to "Ultra", product_path %></li>
but I want it to go directly to the Anchor I have set up on the product page. How is this done in Rails?
The url helper method can take an anchor
hash as a parameter, and will output it as an anchor link:
<li><%= link_to "Ultra", product_path(anchor: 'ultra') %></li>
From the docs:
link_to can also produce links with anchors or query strings:
link_to "Comment wall", profile_path(@profile, anchor: "wall")
# => <a href="/profiles/1#wall">Comment wall</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With