Is there a way to remove code from a Rails view before it is rendered in the browser?
As the title says, is there a way to remove code from a view in a Rails app before it is sent to the browser (regardless of environment)?
For example: If I have commented code in a view and I want to keep开发者_运维技巧 it there for reference but do not want it sent to the browser.
As a reference, Apache Wicket can do this by wrapping the code in a <wicket:remove>
tag. The code inside of that tag will never get delivered to the browser.
If it's commented out HTML you're worried about, simply wrap it in a false if statement:
<% if false %>
<!-- this won't be sent to the client -->
<p>nor will this</p>
<% end %>
or for smaller comments:
<% # my awesome comment %>
If it's Ruby code that's commented out, it won't ever be sent to the client.
(This all assumes you're using ERB, not HAML)
精彩评论