没有@ template.content_tag的Rails助手

时间:2013-06-13 13:51:08

标签: ruby-on-rails ruby-on-rails-3

还有其他方法可以创建帮助程序而不是使用@template.content_tag@template.concat命令吗?

这些看起来太冗长了。

实际上我需要重写一些帮手,如text_field,radio_button,submit等。

1 个答案:

答案 0 :(得分:1)

你想从佣人那里生成HTML,我想?

您可以使用您想要的任何方法简单地生成字符串。如果您致电html_safe,将阻止特殊字符被转义。

def header_helper
  '<div class="header">This is a test</div>'.html_safe
end

在模板中

<%= header_helper %>
<p>This is the content of the section</p>
相关问题