Search code examples
javascriptjqueryruby-on-railsturbolinks

Rails, why does turbolinks stop link_to from showing when I add yield in head?


I have added these two lines in my application.html.erb file <%= yield :gal_img_hover_stylesheet %> and <%= yield :gal_imgs_hover_stylesheet %>

<!DOCTYPE html>
<html>
  <head>
    <title>UserGalleryPictureProject</title>
    <%= csrf_meta_tags %>
    <%= yield :gal_img_hover_stylesheet %>
    <%= yield :gal_imgs_hover_stylesheet %>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
    <%= yield %>
  </body>
</html>

When these are added the link_tos in other actions dont show only on page refresh, they are there in the inspector but are dulled out until I refresh. If I remove yield to these stylesheets the link_to work fine again. I think it has something to do with javascript as removing <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> in application.html.erb links work fine again too.

Is there a way around this because I want the benefits of turbolinks but im not versed enough on where the error is coming from. Obviously when my javascripts arn't loaded into the browser the link_tos work but want to know why.


Solution

  • You can disable turbolinks on the link_to

    <%= link_to('Model', @model, 'data-no-turbolink' => true) %>

    and try to put your two yield header in the below the turbolinks and css code or in the body tag