2013-02-06 28 views
1

我正在嘗試將csv文件導入到rails應用程序中。我也跟着在RailsCast發出的指示>http://railscasts.com/episodes/396-importing-csv-and-excel用於CSV導入的UTF編碼

不管我做什麼,但我仍然得到以下錯誤:

引發ArgumentError在PropertiesController#進口

無效字節的UTF-8的產品序列。

我希望有人可以幫助我找到解決方案。

+3

你寫了什麼代碼?解決這個問題比從頭開始寫一些東西更容易。 –

回答

0

您是否閱讀過CSV文檔? open方法,以及new支持動態多字節字符轉換:

You must provide a mode with an embedded Encoding designator unless your data is in Encoding::default_external(). CSV will check the Encoding of the underlying IO object (set by the mode you pass) to determine how to parse the data. You may provide a second Encoding to have the data transcoded as it is read just as you can with a normal call to IO::open(). For example, "rb:UTF-32BE:UTF-8" would read UTF-32BE data from the file but transcode it to UTF-8 before CSV parses it.