Diego
Diego

Reputation: 4081

Ruby link to anchor on other page

I created an anchor <a name="anchor"></a> on a different page than the link:

<%= link_to image_tag('/assets/image.png'),  newpage_path,:anchor => "anchor" %>

This links to the newpage_path, but starts all the way on top, it's not linking to the anchor. What am I missing?

Upvotes: 0

Views: 474

Answers (2)

pdobb
pdobb

Reputation: 18037

You can (and should) still use a named route for this. Try this:

<%= link_to image_tag('/assets/image.png'), newpage_path(:anchor => "anchor") %>

Search this page for the text anchor for documentation on this: http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to

Upvotes: 1

trh
trh

Reputation: 7339

Try this

<%= link_to image_tag('/assets/image.png'), {:controller => "newpage", :anchor => "anchor"}, :class => "yourstyle" %>

Upvotes: 1

Related Questions