From 005e686187712e33846c9ffb82bf85fc5e38baa6 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 29 Mar 2012 12:44:23 +0200 Subject: [PATCH] dhllabel: They must be encoded with CP1252 and not UTF-8 Fight with rails about the encoding of the label. First we render, then we encode to the closest we have for CP1252 and then we need to set response.body as returning the encoded string will not help us. --- app/controllers/admin/shipments_controller_decorator.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/shipments_controller_decorator.rb b/app/controllers/admin/shipments_controller_decorator.rb index 8f863ec..7609ec1 100644 --- a/app/controllers/admin/shipments_controller_decorator.rb +++ b/app/controllers/admin/shipments_controller_decorator.rb @@ -2,10 +2,15 @@ Admin::ShipmentsController.class_eval do def dhllabel load_shipment name = '%s_dhllabel.csv' % [@order.number] - headers["Content-type"] = "text/plain" + headers["Content-type"] = "text/plain; charset=iso-8859-15" headers["Cache-Control"] = "no-cache, max-age=0, must-revalidate" headers["Pragma"] = "no-cache" headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" headers["Content-Disposition"] = "attachment; filename=\"%s\"" % name + + # Try hard to render it as latin1 + res = render + response.charset = 'iso-8859-15' + response.body = Iconv.conv('iso-8859-15', 'utf-8', res) end end