我有一个需要将视图渲染成字符串的操作。该视图的名称为index.xml.erb。我尝试使用render_to_string来实现这一点:
my_string = render_to_string(layout: false, format: "xml")
render_to_string方法会渲染index.html.erb文件的内容,并将其赋值给my_string变量。我错过了什么吗?
注意: 我知道我可以像这样做:
my_string = render_to_string(:action => "#{self.action_name}.xml.erb")
但我很好奇为什么使用render_to_string时“format”选项没有被采纳。