试图创建一个简单的助手,将其返回到我的视图:
<hr id="effects">我创建的助手如下所示:
def bar(id)
content_tag(:hr, id: id)
end当我打电话的时候
<%= bar("effects") %>帮助程序正确地显示<hr>,但是id像{:id=>"effects"}一样直接显示在页面上。
我假设我做错了这件事,但似乎找不到任何可以帮助我的东西。我很感谢你的帮助。
发布于 2015-12-03 07:41:56
content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
第二个参数是内容,您可以尝试
def bar(id)
content_tag(:hr, "", id: id)
end发布于 2015-12-03 07:43:54
https://stackoverflow.com/questions/34060234
复制相似问题