Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying format: "xml" ignored with render_to_string

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.

like image 785
YWCA Hello Avatar asked Jan 03 '12 22:01

YWCA Hello


1 Answers

This works for me.

render_to_string( :action => "#{self.action_name}", :formats => [:xml] )

like image 129
hoyhoy Avatar answered Sep 19 '22 14:09

hoyhoy