有没有办法在浏览器中渲染之前从 Rails 视图中删除代码?
正如标题所说,有没有办法在将代码发送到浏览器之前从 Rails 应用程序的视图中删除代码(无论环境如何)?
例如:如果我在视图中注释了代码,并且我想将其保留在那里以供参考,但不希望将其发送到浏览器。
作为参考,Apache Wicket 可以通过将代码包装在
标记中来实现此目的。该标签内的代码永远不会传递到浏览器。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您担心它被注释掉了 HTML,只需将其封装在一个 false if 语句中即可:
或者对于较小的注释:
如果注释掉的是 Ruby 代码,则它永远不会发送到客户端。
(这一切都假设您使用的是 ERB,而不是 HAML)
If it's commented out HTML you're worried about, simply wrap it in a false if statement:
or for smaller comments:
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)