Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pjax is awesome, but causes code within #content_for not to be rendered. Here's a solution.
module ApplicationHelper
def content_for_or_pjax(name, &block)
request.headers['X-PJAX'] ? capture(&block) : content_for(name, &block)
end
end
<%= content_for_or_pjax :javascript do %>
<script type='text/javascript'>
alert('Executing JS!');
</script>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment