Can anybodyes help me with XML template rendering and send_data?
I have a controller:
def show
@calculation = Calculation.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @calculation }
format.xml {send_data( :partial=>show.xml.erb, :filename => "my_file.xml" ) }
format.pdf { render :format=>false}
end
end
But I have many errors with "stack level too deep"
If I use
{send_data( @calculation, :filename => "my_file.xml" ) }
I get XML file, but not from my template...
EDIT: I've got a way!
format.xml do
stream = render_to_string(:template=>"calculations/show" )
send_data(stream, :type=>"text/xml",:filename => "test.xml")
end
And all works properly!
Copying the answer from the edited question body in order to remove this question from the "Unanswered" filter:
format.xml do
stream = render_to_string(:template=>"calculations/show" )
send_data(stream, :type=>"text/xml",:filename => "test.xml")
end
~ answer per Dmitry
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