Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Adrien Nhem asked in General

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!

Reply

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: https://www.livecoding.tv/video/new-turbolinks-3-features-with-ruby-on-rails/

Reply

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!

Reply

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.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.