指定格式:“xml”使用 render_to_string 忽略
我有一个需要将视图渲染为字符串的操作。该视图称为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”选项。
I have an action that needs to render a view to string. The view is called index.xml.erb. I am trying to achieve this with render_to_string:
my_string = render_to_string(layout: false, format: "xml")
render_to_string is instead rendering the contents of index.html.erb and assigning it to my_string. What am I missing?
Note: I am aware that I can do something like this:
my_string = render_to_string(:action => "#{self.action_name}.xml.erb")
But I'm curious as to why the "format" option isn't honored with render_to_string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用。
render_to_string( :action => "#{self.action_name}", :formats => [:xml] )
This works for me.
render_to_string( :action => "#{self.action_name}", :formats => [:xml] )