15

J'ai une action qui doit rendre une vue à une chaîne. La vue est appelée index.xml.erb. Je suis en train de réaliser cela avec render_to_string:Spécification du format: "xml" ignoré avec render_to_string

my_string = render_to_string(layout: false, format: "xml") 

render_to_string est la place qui rend le contenu de index.html.erb et l'assigner à my_string. Qu'est-ce que je rate?

Remarque: Je sais que je peux faire quelque chose comme ceci:

my_string = render_to_string(:action => "#{self.action_name}.xml.erb") 

Mais je suis curieux de savoir pourquoi l'option « format » est pas honoré render_to_string.

Répondre

21

Cela fonctionne pour moi.

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

Questions connexes