如果我只是做 Ruby 编程,在什么情况下我需要 eruby
据我了解,eruby 就像 erb - 它可以让你将 ruby 代码粘贴到 HTML 中。 如果有人使用 Rails,他们很可能会使用 erb 或 Haml。
但是如果我不使用Rails,如果我只是进行Ruby编程,在什么情况下我需要eruby?
我想我不明白为什么有人需要输出HTML,如果他们'我只是使用 Ruby 来编写脚本。
As I understand it, eruby is like erb - it lets you stick ruby code into HTML. If someone is using Rails, more than likely they would use erb or Haml.
But if I'm not using Rails, under what cirumstances would I need eruby if I'm just doing Ruby programming?
I guess I don't understand why someone would need to be outputting HTML if they're just using Ruby for writing scripts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
eRuby 不仅仅适用于 HTML - 它允许您将 ruby 嵌入到任何任意文本中。 例如,我见过它在生成 Apache 配置文件的脚本中使用 - 如果您有任何类型的基于文本的输出需要一些动态内容,那么它通常很有用,因为 eRuby 模板通常比一堆模板更容易阅读字符串连接或插值。
eRuby isn't just for HTML - it allows you to embed ruby into any arbitrary text. I've seen it used in scripts that generate Apache configuration files, for instance - it's generally useful if you have any sort of text-based output that needs some dynamic content, as an eRuby template can often be easier to read than a bunch of string concatenation or interpolation.
你刚刚回答了你自己的问题。 如果你的脚本需要输出 HTML,你可以使用 eruby。 除此之外,您可能不需要它。
You just answered your own question. If your script needs to output HTML, you could use eruby. Other than that, you probably don't need it.