如何使用rails中的erb标记呈现html内容?

时间:2013-10-11 07:25:02

标签: ruby-on-rails erb

我正在编写简单的cms引擎,并且遇到动态内容呈现问题,例如我使用erb标记和帮助程序准备一些页面内容,我如何在视图中评估它们? 感谢。

1 个答案:

答案 0 :(得分:1)

如果我理解正确,你想在某个地方存储包含ERB标记的片段,并在运行时在你的rails应用程序的真实模板中评估它们。

在这种情况下,我认为您必须手动调用ERB。这不是很难:

require 'erb'
name = "Rasmus"
template_string = "My name is <%= name %>"
template = ERB.new template_string
puts template.result # prints "My name is Rasmus"

在这篇精彩的文章http://rrn.dk/rubys-erb-templating-system

中阅读更多内容
相关问题