diff options
author | Amiel Martin <amiel@carnesmedia.com> | 2014-06-20 15:49:27 -0700 |
---|---|---|
committer | Amiel Martin <amiel@carnesmedia.com> | 2014-06-24 17:20:24 -0700 |
commit | 6b0e834a194d112585f41deba0a40780d68e38c6 (patch) | |
tree | feac948ca1c91cadc8c9361eeeb56f2bf1bcc965 /actionview | |
parent | 5b23e31771b898cf5e715e72f75dd9427c0a0875 (diff) | |
download | rails-6b0e834a194d112585f41deba0a40780d68e38c6.tar.gz rails-6b0e834a194d112585f41deba0a40780d68e38c6.tar.bz2 rails-6b0e834a194d112585f41deba0a40780d68e38c6.zip |
Use #model_name on instances instead of classes
This allows rails code to be more confdent when asking for a model name, instead of having to ask for the class.
Rails core discussion here: https://groups.google.com/forum/#!topic/rubyonrails-core/ThSaXw9y1F8
Diffstat (limited to 'actionview')
4 files changed, 6 insertions, 6 deletions
diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 789a413c8d..bd8e3b1973 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1815,8 +1815,8 @@ module ActionView object = convert_to_model(@object) key = object ? (object.persisted? ? :update : :create) : :submit - model = if object.class.respond_to?(:model_name) - object.class.model_name.human + model = if object.respond_to?(:model_name) + object.model_name.human else @object_name.to_s.humanize end diff --git a/actionview/lib/action_view/helpers/tags/label.rb b/actionview/lib/action_view/helpers/tags/label.rb index a5bcaf8153..39b2f48c39 100644 --- a/actionview/lib/action_view/helpers/tags/label.rb +++ b/actionview/lib/action_view/helpers/tags/label.rb @@ -40,7 +40,7 @@ module ActionView @object_name.gsub!(/\[(.*)_attributes\]\[\d+\]/, '.\1') if object.respond_to?(:to_model) - key = object.class.model_name.i18n_key + key = object.model_name.i18n_key i18n_default = ["#{key}.#{method_and_value}".to_sym, ""] end diff --git a/actionview/lib/action_view/model_naming.rb b/actionview/lib/action_view/model_naming.rb index e09ebd60df..d42e436b17 100644 --- a/actionview/lib/action_view/model_naming.rb +++ b/actionview/lib/action_view/model_naming.rb @@ -6,7 +6,7 @@ module ActionView end def model_name_from_record_or_class(record_or_class) - (record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name + convert_to_model(record_or_class).model_name end end end diff --git a/actionview/test/activerecord/polymorphic_routes_test.rb b/actionview/test/activerecord/polymorphic_routes_test.rb index fef27ef492..b03fe66e23 100644 --- a/actionview/test/activerecord/polymorphic_routes_test.rb +++ b/actionview/test/activerecord/polymorphic_routes_test.rb @@ -34,8 +34,8 @@ class ModelDelegator < ActiveRecord::Base end class ModelDelegate - def self.model_name - ActiveModel::Name.new(self) + def model_name + ActiveModel::Name.new(self.class) end def to_param |