Ruby on Rails
iconv

What is it?

Iconv is a library used for charset conversion.

iconv in Ruby

Ruby’s Iconv is a wrapper class for the UNIX 95 iconv() function family, which translates string between various encoding systems.

See Open Group’s on-line documents for more details.

Iconv in Rails

There were some iconv related Rails 0.11 Upgrade Problems.

Iconv is required by the SaltedHashLoginGenerator(due to a dependency on “Localization”).

Iconv on Windows

Iconv works out-of-the-box with the latest One-Click Installer (version 1.8.4).

Ruby needs two components for require 'iconv' to work: iconv.so, which is the ruby part, and iconv.dll, which is the iconv library proper. These are missing from One-Click Installer versions 1.8.2 and earlier.

Here is an iconv package with simple installation instructions , which includes both of those components, works with the One-Click Installer 1.8.0-1.8.2, and solves both of the problems detailed below.

missing iconv

Depending on which Ruby distribution you have installed, the iconv ruby extension may not be installed (see if you have ruby\lib\ruby\1.8\i386-mswin32\iconv.so).

The Ruby-mswin32 distribution contains the required files.

Inside the zip, the path to the file is: lib/ruby/1.8/i386-mswin32/iconv.so

missing iconv.dll

If requiring iconv fails complaining about how “iconv.dll was not found”, such as:

rb(main):001:0> require 'iconv'

produces:
error dialog: iconv.dll was not found

LoadError: 126: The specified module could not be found.   - d:/ruby/lib/ruby/1.8/i386-mswin32/iconv.so
        from d:/ruby/lib/ruby/1.8/i386-mswin32/iconv.so
        from d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require'
        from (irb):1

Iconv.dll can be aquired from a number of sources. It is available as a separate download from the gettext for win32 project on SourceForge.

for mingw download the port and (I believe the dev) ports, and build your .so through some means (see http://wiki.rubyonrails.org/rails/pages/Win32MingwInstall).

  1. download libiconv-win32
  2. extract the file bin/iconv.dll to Windows\system32 (or somewhere else on your path, such as \ruby\bin\)
  3. If that doesn’t work, try copying iconv.so to lib\ruby\1.8\i386-mswin32\ as specified in this mailing list post