Rails同样渲染部分为html字符串?

时间:2014-06-06 20:01:28

标签: ruby-on-rails

所以我遇到了一个问题,我希望将部分保存为html字符串并使用该字符串渲染另一部分,但我不断收到双重渲染错误

def fruits 
  fruits = Fruits.all 
  market_html = "#{render partial: 'market', locals: {fruits: fruits}}"  
  render partial: 'super_market', locals {market_html: market_html}
end 

1 个答案:

答案 0 :(得分:2)

您想要render_to_string吗?

market_html = render_to_string partial: 'market', locals: {fruits: fruits}