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.
This works for me.
render_to_string( :action => "#{self.action_name}", :formats => [:xml] )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With