Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanwalsh/2591845 to your computer and use it in GitHub Desktop.
Save evanwalsh/2591845 to your computer and use it in GitHub Desktop.
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