Localizing attributes when using I18n

Currently I’m developing a multilingual app on rails 2.2. I liked very
much the idea of Xavier Defrang to provide a locale-aware accessor for
the fields that needs a translation:

I modified code a little to make it work with rails 2.2:

def self.localize(*attribute_names)
attribute_names.each do |attribute_name|
class_eval %{
def #{attribute_name}
localized_method = "#{attribute_name}
return send(localized_method.to_sym) if respond_to?

it works fine for :show, :index, :new. But when I’m trying to create
or update, I get the following error:

ActiveRecord::UnknownAttributeError in NewsitemsController#create

unknown attribute: _body

What’s wrong? Please, help.

Problem solved by using plugin:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs