I need to generate a file in rails with encoding iso-8859-15. To make this, I am using the following code:
File.open( "#{ Rails.root }/tmp/#{ id }", 'w:iso-8859-15:iso-8859-15' ) { |f| f << Model.info_in_iso-8859-15 }
respond_to do |format|
format.text { send_file( route, filename: 'info', type: 'text/plain; charset=iso-8859-15; header=present' ) }
end
The problem is that when I see the encoding of the file, it is using iso-8859-1, so I have problems with some symbols like € and so on. I have been surfing on Intenet for hours but I can not find anything for ruby.
Thanks in advance.
EDIT:
This is the method that I use to convert to iso-8859-15:
def normalize_to_iso8859( string )
if string and string.class == String
string.gsub(/[\u201c\u201d]/, '"').gsub(/[\u2013]/, '-').encode( "ISO8859-15" )
else
string
end
end