Reputation:
How to use this new Turbolinks 3.0 (branch: 'master') with Rails 4.2?
I'm trying and I got from Chrome this error:
Uncaught SyntaxError: Unexpected token :
If I use partial replacement like this:
<%= link_to "Something", root_path %>
and then in 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 is reloaded entirely and I got that error. How to do?
EDIT THE DAY AFTER
I have Rails 4.2.1 standard.
In Gemfile I added:
gem 'turbolinks', :github => 'rails/turbolinks', :branch => 'master'
Now in one controller I have:
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 another like this:
def red_category
render partial: 'category_choose', change: 'categoriesdiv'
end
also if I add the , turbolinks: true
at the end of each line, NOTHING!
My chrome window's title is changing in a laconic "undefined", but if I use the Chrome developer tool it says to me in "Network" tab that the request to the server is complete with "GET" method, "304" status, "Text/Javascript" type, all without errors.
In the 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?
Upvotes: 5
Views: 3262
Reputation: 58455
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 change area, I'm not certain about that bit but I would go for something like this:
<%= link_to "Something", root_path, remote: true, { :change => 'areaDiv' } %>
Upvotes: 0
Reputation: 81
Turbolinks is tricky, either way here is a resource worth spending some time on. I see slight syntax differentiation between what you write and how the do.
https://github.com/rails/turbolinks/issues/448
Upvotes: 1