Created
October 18, 2011 15:20
pjax is awesome, but causes code within #content_for not to be rendered. Here's a solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def content_for_or_pjax(name, &block) | |
request.headers['X-PJAX'] ? capture(&block) : content_for(name, &block) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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
I use a simple layout for PJAX responses:
This allows me to have the views be pretty agnostic about whether or not PJAX is used.