Skip to main content

How can I implement back button and bookmark history with turbolinks ajax and rails 4?

General • Asked by Adrien Nhem

Hi guys!

I have been asking this question everywhere... basically I am building a user dashboard and it load the main div with ajax calls. I wanted to know how can I update the URL when an ajax call is made so that I can refresh the page with the same ajax partial and then use the back button as well? Any idea is more than welcome. I have very basic knowledge about javascript.

I am using turbolinks, ruby on rails 4.

Many thanks!

Turbolinks actually does all of what you're describing with the new partial functionality. I made a video on it on another service that I was fiddling with.

You can check out the video here:

Thank you Chris for your reply. But I can't make it work.

I made sure that I was using Turbolinks 3.

The dashboard that I am building only use get request that links to a show method on different controllers.

The controller that handles the redirection to the different partials from the different action of the different controllers is profiles_controller.rb. The layout includes a permanent sidebar menu.

What I have tried to do

  1. And the div that is always updated is #dashboard to which I have added data-turbolinks-temporary as it is supposed to be modified.
  2. Added remote: true to the link_to
  3. In the lectures controller I have added render partial: "show", change: 'dashboard' So that it is supposed to replace all the elements within the div ided dashboard.
  4. Added Turbolinks.visit(url, { change: ['dashboard'] })

Did I actually missed something because when I click on the link_to, the partial is rendered but the url is not updated and if then I hit refresh or back button it redirects me to the very first page instead of reloading the same partial? Maybe I am trying to do something different? Or just lost ^

Thanks for your time!

Hmm that sounds right. Are you able to share an example app that I could take a look at? Not sure I can give you any more pointers without fiddling with some code.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.