私はアプリケーションでXMLファイルを生成するためにNokogiriを使用しています。このファイルを保存したいので、このファイルをダウンロードするフォルダをユーザーが選択できるダイアログボックスを表示します。私は、私はビューからアクションを呼び出すときRails send_dataはファイルを保存しません
get '/dbsinc/download'
が、それはXMLを保存しません。私はこのように定義されたルートを持っている
def download
require 'nokogiri'
if owner_signed_in?
@slips = current_owner.slips
builder = Nokogiri::XML::Builder.new do |xml|
xml.cedolini{
@slips.each do |slip|
xml.cedolino{
xml.codicecliente_ slip.client_code
xml.data_ slip.day.to_s
xml.ordini{
slip.product_slips.each do |order|
xml.ordine {
xml.codicearticolo_ order.product_code
xml.descrizionearticolo_ order.product_description
xml.ammontare_ order.amount.to_s
}
end
}
}
end
}
end
file = builder.to_xml
send_data file, :type => 'text/xml; charset=UTF-8;', :disposition => "attachment; filename=db.xml"
end
end
: これは私のコントローラ内のアクションです私のアクションのURLが付いた新しいページを見てください。ページにはXMLファイルが表示されていますが、ファイルを保存するダイアログボックスは表示されません。 どこが間違っていますか? `ポスト「dbsinc /ダウンロード」
そして、私の見解で、私はこのようにリンクを定義した:
<%= link_to 'Download ', {controller:'dbsinc', action:'download'}, method: :post %>
をそしてそれは、ダウンロードダイアログを作品のおかげ
「endit do」とは何ですか? –
私はコピーアンドペーストで間違いを犯しました。それはちょうど最後のステートメントです。私は今正しいコードで編集しました。 –
インデントを修正すると読みやすさに役立つかもしれません。 –