如何在Rails 4.2中使用新的Turbolinks 3.0(分支:'master')?
我正在尝试,但在Chrome中遇到了以下错误:
Uncaught SyntaxError: Unexpected token :
如果我像这样使用部分替换:
<%= link_to "Something", root_path %>
接下来在同一页中:
<script> Turbolinks.visit(url, { change: 'areaDiv' }); </script>
根据文档:https://github.com/rails/turbolinks#partial-replacements-with-turbolinks-30 当整个页面被重新加载时,我遇到了错误。怎么办? 次日编辑 我使用的是标准版Rails 4.2.1。
在Gemfile中我添加了:
gem 'turbolinks', :github => 'rails/turbolinks', :branch => 'master'
现在在一个控制器中,我有以下代码:
def ok_category
render plain: "Ok", change: 'categoriesdiv'
end
也许可以这样做:
def red_category
redirect_to "http://www.google.com", change: 'categoriesdiv'
end
或者像这样的另一个:
def red_category
render partial: 'category_choose', change: 'categoriesdiv'
end
另外,如果我在每行末尾添加turbolinks: true
,仍然什么都没有发生!
我的Chrome窗口标题变成了简洁的“undefined”,但如果我使用Chrome开发者工具,在“网络”标签中它告诉我服务器请求已完成,使用“GET”方法,状态为“304”,类型为“Text/Javascript”,全部没有错误。
在application.html.erb文件中,我有:
<!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?