Forum: Ruby on Rails Localizing attributes when using I18n

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.
Colorblind (Guest)
on 2009-05-03 13:25
(Received via mailing list)
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:
http://defrang.com/articles/2005/12/02/playing-wit...

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}_\#
{I18n.locale.to_s}"
            return send(localized_method.to_sym) if respond_to?
(localized_method)
          #{attribute_name}
        end
      }
    end
  end

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.
Colorblind (Guest)
on 2009-05-03 17:53
(Received via mailing list)
This topic is locked and can not be replied to.