An issue I ran into when using the
pjax_rails gem, and useful advice if you need additional content delivered besides the
I ran into this issue and my googlings returned little information, so I PR’d additions to the
pjax_rails gem readme, and thought I’d
make a post while I’m at it for anyone who runs into this issue in the future.
When you add
pjax_rails to your project, it ensures every pjax request does not render your layouts, and only the relevant view.
But you may run into the need to include additional content, such as a contextual menu, outside of the particular views.
You can specify a particular layout to render for pjax requests, by overriding the
pjax_layout method in your controllers.
1 2 3 4 5
And also creating the relevant file
You’ll likely want
to render the same content, so I recommend moving that content (the
data-pjax-container element and its children) into a
partial, and then rendering that out in both
As a tip, I add a
h2 title to
pjax.html.erb when I want to debug what’s pjax and what’s not.