Rails 4, Turbolinks 3, partial replacement

How to use this new Turbolinks 3.0 (branch: "master") with Rails 4.2?

I try and I got this error from Chrome:

Uncaught SyntaxError: Unexpected token:

If I use partial replacement as follows:

<%= link_to "Something", root_path %> 

and then on the same page:

 <script> Turbolinks.visit(url, { change: 'areaDiv' }); </script> 

according to docs: https://github.com/rails/turbolinks#partial-replacements-with-turbolinks-30

The page reloads completely and I got this error. How to do it?

CHANGE DAY AFTER

I have a Rails 4.2.1 standard.

In the gemfile, I added:

 gem 'turbolinks', :github => 'rails/turbolinks', :branch => 'master' 

Now in one controller I:

 def ok_category render plain: "Ok", change: 'categoriesdiv' end 

or maybe this:

  def red_category redirect_to "http://www.google.com", change: 'categoriesdiv' end 

or other similar:

 def red_category render partial: 'category_choose', change: 'categoriesdiv' end 

also, if I add , turbolinks: true at the end of each line, NOTHING!

The name of my chrome window changes in a concise "undefined", but if I use the Chrome developer tool, it tells me on the "Network" tab that the server request has been completed with the "GET" method, 304, type "Text / Javascript", all without mistakes.

In application.html.erb, I have:

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Hello!</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <div class="container"> <div id="test"><%= Time.now.to_s %></div> <div id="links"><%= link_to "Testmylink", ok_category_path(1), remote:true %></div> <%= yield %> <div id="categoriesdiv" data-turbolinks-temporary>Yes yes!</div> <footer class="footer"> <p class="text-center">Hello!</p> </footer> </div> </body></html> 

What is wrong with me?

+5
source share
2 answers

Turbolinks is difficult, anyway, it's a resource worth spending some time. I see a slight syntactic differentiation between what you write and how they do it.

https://github.com/rails/turbolinks/issues/448

+1
source

When using link_to the remote parameter tells rails to use turbolinks to follow the link, so I think you need remote: true .

You also need to add your scope of change, I'm not sure about this, but I would go for something like this:

 <%= link_to "Something", root_path, remote: true, { :change => 'areaDiv' } %> 
0
source

All Articles