Neil
Neil

Reputation: 5178

Rails: Anchor Tag to jump to location on same page without sending a new request and having to re-render the page

This is how I thought you do this. For the place you want to jump to, you simply specify an id:

<h1 id="top_of_blogs_list">TOP OF WEBPAGE</h1>

And then if you want to jump there from somewhere on a webpage via a link, you simply specify an anchor tag for that link:

  <%= link_to "Back to Top", blogs_path(anchor: "top_of_blogs_list")%>

The issue is that this is sending a brand new request to the server and re-rendering the entire page. I do not want to send a new request to the server. I want to keep the current page as it is currently rendered, and simply jump up to where that id of "top_of_blogs_list" is specified.

Perhaps this must be done using javascript?

Upvotes: 0

Views: 944

Answers (1)

Mike Desjardins
Mike Desjardins

Reputation: 460

You don't need the blogs_path. This should suffice:

<%= link_to "Back to Top", '#top_of_blogs_list' %>

Upvotes: 1

Related Questions