Reputation: 12304
I have a layout page with this block in the tag:
# application.html.erb
...
<% if content_for? :head %>
<%= yield :head %>
<% end %>
and here is the block that is yielded:
# index.html.erb
...
<% content_for :head do %>
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/plug-ins/be7019ee387/integration/bootstrap/3/dataTables.bootstrap.css">
<script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="//cdn.datatables.net/plug-ins/be7019ee387/integration/bootstrap/3/dataTables.bootstrap.js"></script>
<% end %>
If I go to the index page directly, or perform a refresh on the index page, the :head block is added to the layout. However, if I redirect to index from another page (for e.g. new.html.erb in the same controller, or a different controller) without rendering index first, the :head block is not copied over.
I would like to know why this is happening, though I suspect that this has something to do with turbo-link.
Any input is appreciated.
Upvotes: 1
Views: 29
Reputation: 11395
Yes, the problem is Turbolinks. Turbolinks replaces only the body and the title in the head. The other head elements are kept intact.
If you want to load external scripts and stylesheets, you can place them on the body.
Upvotes: 1