Qualcuno può aiutarmi con il rendering del modello XML e send_data?Come eseguire il rendering del modello XML e quindi utilizzare SEND_DATA in Ruby on Rails 3.2.8?
ho un 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
Ma ho molti errori con "livello di stack troppo in profondità"
Se uso
{send_data(@calculation, :filename => "my_file.xml") }
ottengo file XML, ma non da il mio modello ...
MODIFICA: Ho un modo!
format.xml do
stream = render_to_string(:template=>"calculations/show")
send_data(stream, :type=>"text/xml",:filename => "test.xml")
end
E tutto funziona correttamente!
Potrebbe pubblicare il tuo intera traccia? – sunnyrjuneja
SystemStackError in CalculationsController # mostrare livello risma troppo in profondità Rails.root: C: /RubyStack-3.2.5-0/examplexml Application Trace | Traccia del framework | Trace completa actionpack (3.2.5) lib/action_dispatch/middleware/reloader.rb: 70 – Dmitry
posso avere un risultato nel mio Chrome con: format.xml {render: format => false} Ma solo schermo, non file da scaricare – Dmitry