This project is archived and is in readonly mode.

#4273 ✓invalid
Raffael Schmid

autosave error messages cannot be translated (i18n)

Reported by Raffael Schmid | March 26th, 2010 @ 12:05 PM

This seems to be similar to #3147.

ActiveRecord::Schema.define do
  create_table(:owners) { |o| o.string :username }
  create_table(:items)  { |i| i.string :property }

class Owner < ActiveRecord::Base
  has_one :item, :autosave => true
  validates_presence_of :username

class Item < ActiveRecord::Base
  validates_presence_of :property

I18n.backend.store_translations :en, :"" => "Testing1"

owner =

item = Item.create

This code above will result in
["Item property can't be blank", "Username can't be blank"] and
["Testing1 can't be blank"]

The first output is not as expected. It should be like ["Testing1 can't be blank", "Username can't be blank"].

With the following patch, it works as expected.

Maybe there is a better fix, but this works for my project.

Comments and changes to this ticket

  • Raffael Schmid

    Raffael Schmid March 26th, 2010 @ 12:27 PM

    • Title changed from “nested attributes error messages cannot be looked up” to “autosave error messages cannot be translated (i18n)”

    Sorry, patch works for my test in the description but not in my rails-project.

    Following patch works for both.

  • José Valim

    José Valim March 26th, 2010 @ 11:01 PM

    • State changed from “new” to “invalid”

    You need to have the translation under "" and "". You can use a symbol to symlink translations (check I18n documentation for more information). Notice that we cannot rely on constantize, since it would fail in some cases like:

    has_many :super_projects, :class_name => "Project"

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket