aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorAmiel Martin <amiel@carnesmedia.com>2014-06-20 15:49:27 -0700
committerAmiel Martin <amiel@carnesmedia.com>2014-06-24 17:20:24 -0700
commit6b0e834a194d112585f41deba0a40780d68e38c6 (patch)
treefeac948ca1c91cadc8c9361eeeb56f2bf1bcc965 /actionpack/lib
parent5b23e31771b898cf5e715e72f75dd9427c0a0875 (diff)
downloadrails-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 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/model_naming.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb10
2 files changed, 6 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/model_naming.rb b/actionpack/lib/action_controller/model_naming.rb
index 785221dc3d..2b33f67263 100644
--- a/actionpack/lib/action_controller/model_naming.rb
+++ b/actionpack/lib/action_controller/model_naming.rb
@@ -6,7 +6,7 @@ module ActionController
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/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index bd3696cda1..746e4cd245 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -249,9 +249,9 @@ module ActionDispatch
model = record.to_model
name = if record.persisted?
args << model
- model.class.model_name.singular_route_key
+ model.model_name.singular_route_key
else
- @key_strategy.call model.class.model_name
+ @key_strategy.call model.model_name
end
named_route = prefix + "#{name}_#{suffix}"
@@ -279,7 +279,7 @@ module ActionDispatch
parent.model_name.singular_route_key
else
args << parent.to_model
- parent.to_model.class.model_name.singular_route_key
+ parent.to_model.model_name.singular_route_key
end
}
@@ -292,9 +292,9 @@ module ActionDispatch
else
if record.persisted?
args << record.to_model
- record.to_model.class.model_name.singular_route_key
+ record.to_model.model_name.singular_route_key
else
- @key_strategy.call record.to_model.class.model_name
+ @key_strategy.call record.to_model.model_name
end
end