Forum: Ruby on Rails utf-8 BIG problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
brutyn_nick (Guest)
on 2005-12-09 13:35
(Received via mailing list)
hey,

------------------
i have change my db to utf8-general-ci, now all the characters are
correct in
the database, i need this for exporting to pdf en excel. now i can also
import
from csv, characters like éàï....

But the display is then fucked up. i get wierd symbols
-------------------

Another situation:
I have seen a post here to add to environment.rb:
$KCODE = 'UTF8'
require 'jcode'

and to application.rb:
	before_filter :configure_charsets
	after_filter :fix_unicode_for_safari

	def parse_errors(obj)
		return nil if obj.nil?

		str = "<ul>"
		obj.errors.each_full do |msg|
		str += "<li>" + msg +"</li>"
		end
		str += "</ul>"
		return str
	end

    	def configure_charsets
        @headers["Content-Type"] = "text/html; charset=utf-8"
        suppress(ActiveRecord::StatementInvalid) do
          ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
        end
    end

then the display is correct but when i export to pdf and excel i get the
wierd
characters again. and when i want to import form csv, u can read here
http://article.gmane.org/gmane.comp.lang.ruby.rails/33840

but i need all correct characters in the database, cuz i also work with
xml and
soap and ajax.

-----------

I prefer to use the 1st solution (correct import and export, incorrect
display)
and find a solution for the display.

Can anyone help me??

thanks in advance
brutyn_nick (Guest)
on 2005-12-09 18:26
(Received via mailing list)
hey, if found a temp solution for this

for showing, editing, xml ==>> u need utf8
in the def

@headers["Content-Type"] = "text/html; charset=utf-8"
suppress(ActiveRecord::StatementInvalid) do
	 ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
end

for pdf, excel, import csv ==>> u need latin1, iso-8859-1
in the def

@headers["Content-Type"] = "application/pdf; charset=iso-8859-1"
suppress(ActiveRecord::StatementInvalid) do
	ActiveRecord::Base.connection.execute 'SET NAMES latin1'
end
This topic is locked and can not be replied to.