除了使用 @template.content_tag
和 @template.concat
命令之外,还有其他创建助手的方法吗?
这些看起来太冗长了。
实际上我需要重写一些帮助程序,例如 text_field、radio_button、submit 等。
最佳答案
你想从你的助手生成 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>
关于ruby-on-rails - 没有 @template.content_tag 的 Rails 助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17088816/