From 5d0300d56315e50e8e6261fcc5ac923170d14739 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Mon, 24 Jan 2011 02:50:23 +0300 Subject: [PATCH 2/2] [6273] I18n labels for nested attributes fix --- actionpack/lib/action_view/helpers/form_helper.rb | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index d7b9e0b..7994061 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -894,7 +894,11 @@ module ActionView label_tag(name_and_id["id"], options, &block) else content = if text.blank? - I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence + # As there're no universal mapping between object_name and I18n YAML file in case + # of nested attributes we have to manually strip indices from object names, e.g.: + # object_name is "person[interests_attributes][0]", but YAML should contain only + # "person[interests_attributes]" and we're removing "[0]" index + I18n.t("helpers.label.#{object_name}.#{method_name}".gsub(/(\[.*?\])\[\d+\]/, '\1'), :default => "").presence else text.to_s end -- 1.7.3.5