Search code examples
ruby-on-railsturbolinks

Turbolinks and code in Application layout


Ok, first time using Turbolinks. Overall, I'm pleased, but I have one issue: there is code in my application layout (simple header code, shows your info if you are logged in, otherwise a login form) that doesn't get reloaded when the data changes.

This makes sense - as its not within a yield, its in my application layout and Turbolinks shouldn't run it.

But is there an easy way to trigger turbolinks to regenerate that portion of the page?


Solution

  • Turbolinks

    A big problem you'll find with Turbolinks is the way in which it will only update the <body> of your page - leaving the <head> intact.

    This means if you have logic in the <head> of your HTML layout, it won't change if you're loading a page with the same <head> area.

    --

    Setup

    The solution I use is to just put the logic in the <body> of the page. We use the following:

    #app/views/layouts/application.html.erb
    <body>
       <% if user_signed_in? %>
           ...
       <% else %>
           ...
       <% end %>
    

    This works for us in every application we've done it in - all using turbolinks.