开发者

Rails: Multiple renders in a content_tag?

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 =开发者_如何学Go "#{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


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:

template = content_tag(:div) do      
  fields = ''
  form_builder.fields_for(association, object) do |f|
    formats.each do |format|
      partial = "#{format}_fields"
      fields << render(:partial => partial, :locals => { :f => f })
    end
  end
  fields
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜