aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view
diff options
context:
space:
mode:
authorMaarten Claes <maartencls@gmail.com>2015-01-22 21:38:29 +0100
committerMaarten Claes <maartencls@gmail.com>2015-01-22 23:00:34 +0100
commitee3dd2f0ff1820804888cb3a7475dd593deb0212 (patch)
tree980abcaa8193bf774ab901fe187565d36242782a /actionview/lib/action_view
parent139c232b075da940cdf1042dcaad4c3b514908c9 (diff)
downloadrails-ee3dd2f0ff1820804888cb3a7475dd593deb0212.tar.gz
rails-ee3dd2f0ff1820804888cb3a7475dd593deb0212.tar.bz2
rails-ee3dd2f0ff1820804888cb3a7475dd593deb0212.zip
Convert with `to_model` before calling ActiveModel methods on `object`
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r--actionview/lib/action_view/helpers/tags/label.rb10
-rw-r--r--actionview/lib/action_view/helpers/tags/placeholderable.rb12
2 files changed, 14 insertions, 8 deletions
diff --git a/actionview/lib/action_view/helpers/tags/label.rb b/actionview/lib/action_view/helpers/tags/label.rb
index 08a23e497e..c44cc57468 100644
--- a/actionview/lib/action_view/helpers/tags/label.rb
+++ b/actionview/lib/action_view/helpers/tags/label.rb
@@ -18,15 +18,19 @@ module ActionView
@object_name.gsub!(/\[(.*)_attributes\]\[\d+\]/, '.\1')
if object.respond_to?(:to_model)
- key = object.model_name.i18n_key
+ model = object.to_model
+ end
+
+ if model
+ key = model.model_name.i18n_key
i18n_default = ["#{key}.#{method_and_value}".to_sym, ""]
end
i18n_default ||= ""
content = I18n.t("#{@object_name}.#{method_and_value}", :default => i18n_default, :scope => "helpers.label").presence
- content ||= if object && object.class.respond_to?(:human_attribute_name)
- object.class.human_attribute_name(method_and_value)
+ content ||= if model && model.class.respond_to?(:human_attribute_name)
+ model.class.human_attribute_name(method_and_value)
end
content ||= @method_name.humanize
diff --git a/actionview/lib/action_view/helpers/tags/placeholderable.rb b/actionview/lib/action_view/helpers/tags/placeholderable.rb
index ae67bc13af..690ba93ab5 100644
--- a/actionview/lib/action_view/helpers/tags/placeholderable.rb
+++ b/actionview/lib/action_view/helpers/tags/placeholderable.rb
@@ -12,17 +12,19 @@ module ActionView
method_and_value = tag_value.is_a?(TrueClass) ? @method_name : "#{@method_name}.#{tag_value}"
if object.respond_to?(:to_model)
- key = object.class.model_name.i18n_key
+ model = object.to_model
+ end
+
+ if model
+ key = model.model_name.i18n_key
i18n_default = ["#{key}.#{method_and_value}".to_sym, ""]
end
i18n_default ||= ""
placeholder ||= I18n.t("#{object_name}.#{method_and_value}", :default => i18n_default, :scope => "helpers.placeholder").presence
-
- placeholder ||= if object && object.class.respond_to?(:human_attribute_name)
- object.class.human_attribute_name(method_and_value)
+ placeholder ||= if model && model.class.respond_to?(:human_attribute_name)
+ model.class.human_attribute_name(method_and_value)
end
-
placeholder ||= @method_name.humanize
@options[:placeholder] = placeholder