rails/rails — Issue #3648: Rails 3.1.2.rc2, issue with activerecord attributes names defined in config/locales/*.yml
Author: stanislaw
Created: 2011-11-16 21:38:49+00:00
State: open

Hello!

I have two models Post and Comment:

class Post < ActiveRecord::Base

has_many :comments
validates_associated :comments

accepts_nested_attributes_for :comments, :allow_destroy => true ,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end

class Comment < ActiveRecord::Base

validate :some_custom_validation_adding_to_base

private

def some_custom_validation_adding_to_base
errors.add(:base, "Something strange happening") if name.size < 10
end
end

If I try to create @post record with associated comment having non-empty name with size less than 10 - my custom validation adds error message to :base so errors.full_messages then contain string like "Comments base Something strange happening"

I want to write a string into config/locales/en.yml to have my custom string instead of 'Comments base'.

The problem is when I try to put into en.yml:

en:
# This works!
# attributes:
# comments:
# base:
# "Associated comments"

activerecord:
attributes:
post:
comments: "`post.comments works`"
# This doesn't work giving "couldn't parse YAML at line 10 column 15 (Psych::SyntaxError)"
# base: "Associated comments"

activemodel-3.1.2.rc2/lib/active_model/translation.rb #54-55, #inspect on 'defaults' variable gives:
[:"activerecord.attributes.post.comments.base", :"attributes.comments.base", "Comments
base", "Comments.base"]

And while the second item of an array works, it would be more consistent to have first one working too also.

I hope it makes sense.

Test app created for this issue: https://github.com/stanislaw/associated_base_issue

Thanks!