# Labels, I18n and accepts\_nested\_attributes\_for

**URL:** <https://www.ruby-forum.com/t/labels-i18n-and-accepts-nested-attributes-for/199774>\
**Category:** Rails I18n\
**Created:** [November 29, 2010, 7:39am UTC](https://www.ruby-forum.com/t/labels-i18n-and-accepts-nested-attributes-for/199774 "2010-11-29T07:39:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 29, 2010, 7:39am UTC](https://www.ruby-forum.com/t/labels-i18n-and-accepts-nested-attributes-for/199774/1 "2010-11-29T07:39:24Z")

</div>

Note: I am using Rails 2.3.10.

Normally, you can use Rails I18n system to generate label text.

For example, suppose you have a Person class with a name attribute. And  
this ERB:  
\<%= form\_for @person do |f| %\>  
\<%= f.label :name %\>  
\<%= f.text\_field :name %\>  
\<% end %\>

And youd construct your en.yml like so:  
en:  
helpers:  
label:  
name: your name

However, this doesnt work very well with related objects and  
accepts\_nested\_attributes\_for. Suppose you have the same Person class as  
before. And person has\_many :activities (likewise, activity belongs\_to  
:person) and accepts\_nested\_attributes\_for :activities.

Now your ERB looks like this:  
\<%= form\_for @person do |f| %\>  
\<%= f.label :name %\>  
\<%= f.text\_field :name %\>  
\<% f.fields\_for :activities do |a| %\>  
\<%= l.label :difficulty %\>  
\<%= l.text\_field :difficulty %\>  
\<% end %\>  
\<% end %\>

Various combinations indentation of person / activities / difficulty in  
my en.yml file didnt work. So I looked inside rails to see whats going  
on.

The relevant code is in  
actionpack-2.3.10/lib/action\_view/helpers/form\_helper.rb. The method  
used is  
def to\_label\_tag(text = nil, options = {})  
on line 758.

And the code doing the work is:  
content = if text.blank?  
i18n\_label =  
I18n.t(“helpers.label.#{object\_name}.#{method\_name}”, :default =\> )  
i18n\_label if i18n\_label.present?  
else  
text.to\_s  
end

The problem is you end up with a set of labels like:  
helpers.label.person[activities\_attributes][0].difficulty  
helpers.label.person[activities\_attributes][1].difficulty  
helpers.label.person[activities\_attributes][2].difficulty

Is there a way you can put wildcards in YAML? If not, is there some  
other way around this limitation? If not, this seems like a bug in  
Rails, and Ill file a lighthouse ticket.

Paul
