Last active
August 29, 2015 14:09
-
-
Save coldnebo/4e9774486fb0c7a62617 to your computer and use it in GitHub Desktop.
capture doesn't work outside of the view it's in?
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
alert('something'); |
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
def broken_helper | |
render_to_string('another_partial', format: false) | |
end | |
def working_helper | |
%{alert('something');}.html_safe | |
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
<!-- view template --> | |
<% @myjs = capture do %> | |
<%= broken_helper %> | |
<% end %> | |
<%= @myjs %> | |
<!-- output: "something" --> | |
<!-- alternate approach --> | |
<% content_for(:javascript) do %> | |
<%= broken_helper %> | |
<% end %> | |
<!-- working approach --> | |
<% content_for(:js2) do %> | |
<%= working_helper %> | |
<% 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
<!-- layout template --> | |
<script><%= @myjs %></script> | |
<!-- output: "" --> | |
<script><%= yield(:javascript) %></script> | |
<!-- output: "" --> | |
<script><%= yield(:js2) %></script> | |
<!-- output: "alert('something');" --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
built this out into a test repo: coldnebo/rails_content_issue@3f4b135#diff-c41b830814781a1cd840bfed7a09e6b8R15
confirmed that the problem is in Rails3, but fixed in Rails4. see https://github.com/coldnebo/rails_content_issue/blob/master/README.md