Rails:content_tag 中的多个渲染?
我在辅助方法中遇到了这个毛茸茸的问题:
template = content_tag(:div) do
form_builder.fields_for(association, object) do |f|
formats.each do |format|
partial = "#{format}_fields"
render(:partial => partial, :locals => { :f => f })
end
end
end
不幸的是,如果我在 content_tag< 中执行
each
循环,template
似乎实际上没有任何内容/代码>。
我有什么想法可以实现这一点吗?我需要为此content_tag
渲染
多个部分。
注意:我正在运行 Rails 3.0.3
I've got this hairy bit in a helper method:
template = content_tag(:div) do
form_builder.fields_for(association, object) do |f|
formats.each do |format|
partial = "#{format}_fields"
render(:partial => partial, :locals => { :f => f })
end
end
end
Unfortunately template
doesn't seem to actually have any content if I do the each
loop within the content_tag
.
Any ideas how I could pull this off? I need to render
multiple partials for this content_tag
.
Note: I'm running Rails 3.0.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码看起来有点可疑,你到底想做什么?使用带有布局的部分可能比尝试在助手中执行此操作更好。
我认为
render(:partial => )
将返回内容而不是将其连接到输出流,所以也许尝试像这样编写你的助手:This code looks a little suspect, what is it exactly you want to do? You might be better served using a partial with a layout than trying to do this in a helper.
I think
render(:partial => )
will return the content and not concat it to the output stream, so maybe try writing your helper like this: