Firebird on Rails encoding accent right

So today, I had a great achivment ! (A personal happyness 😛 )

The problem:

I HAVE to use a Rails App with Firebird DB 1.5 encoding: NONE and it has accents !

The deal : Portuguese is the language we Speak in Brazil ( Brasil), it has a lot of accents (acentos) so to get the right encode on the web as most programers are aware of, we gotta use charset= ISO-8859-1 or UTF-8 and as long as my tables is shared with Delphi App that are using encoding: none, as the newer app programmer I have to adapt 😛

During research I found this guy:, and his job seems great.. but I not looking fwd to translate the DB, still, I will use his Ruby function

Solution: set a LIB file like this:


  def iconvert(str, encoding_from="iso-8859-1//ignore", encoding_to = "utf-8")
    i = encoding_to, encoding_from
    utf_str = ""
      utf_str < e
      utf_str << e.success
      ch, str = e.failed.split(//, 2)
      utf_str << "?" "FAIL !! char:#{ch}"
    return utf_str
  def ireverse(str)
    iconvert(str, "utf-8", "iso-8859-1//ignore" )

At the App Controller:

class ApplicationController < ActionController::Base
  helper :all 
  require 'iconv'
  require 'conversor.rb'

So now everytime you have to display data from the database use: iconvert(String) !

To save the data define in your model for each String or Text field:


# "nome" is the field i am retro converting
  def nome=(valor)
    write_attribute(:nome, ireverse(valor))

I spent a lot of hours on this research.. I wish i knew how to create plugins..
*Maybe you have to download the Iconv class if your Ruby isn't new enough
**First page on google ! for "rails firebird encoding", "rails firebird acento" yay!


3 thoughts on “Firebird on Rails encoding accent right

  1. Pingback: Firebird News » Firebird on Rails encoding accent right

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s