aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/naming.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/lib/active_model/naming.rb')
-rw-r--r--activemodel/lib/active_model/naming.rb32
1 files changed, 20 insertions, 12 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb
index af89391413..7ba439fb3e 100644
--- a/activemodel/lib/active_model/naming.rb
+++ b/activemodel/lib/active_model/naming.rb
@@ -218,6 +218,14 @@ module ActiveModel
# Returns an ActiveModel::Name object for module. It can be
# used to retrieve all kinds of naming-related information
# (See ActiveModel::Name for more information).
+ #
+ # class Person < ActiveModel::Model
+ # end
+ #
+ # Person.model_name # => Person
+ # Person.model_name.class # => ActiveModel::Name
+ # Person.model_name.singular # => "person"
+ # Person.model_name.plural # => "people"
def model_name
@_model_name ||= begin
namespace = self.parents.detect do |n|
@@ -254,11 +262,11 @@ module ActiveModel
# Returns string to use while generating route names. It differs for
# namespaced models regarding whether it's inside isolated engine.
#
- # For isolated engine:
- # ActiveModel::Naming.route_key(Blog::Post) #=> post
+ # # For isolated engine:
+ # ActiveModel::Naming.route_key(Blog::Post) #=> post
#
- # For shared engine:
- # ActiveModel::Naming.route_key(Blog::Post) #=> blog_post
+ # # For shared engine:
+ # ActiveModel::Naming.route_key(Blog::Post) #=> blog_post
def self.singular_route_key(record_or_class)
model_name_from_record_or_class(record_or_class).singular_route_key
end
@@ -266,11 +274,11 @@ module ActiveModel
# Returns string to use while generating route names. It differs for
# namespaced models regarding whether it's inside isolated engine.
#
- # For isolated engine:
- # ActiveModel::Naming.route_key(Blog::Post) #=> posts
+ # # For isolated engine:
+ # ActiveModel::Naming.route_key(Blog::Post) #=> posts
#
- # For shared engine:
- # ActiveModel::Naming.route_key(Blog::Post) #=> blog_posts
+ # # For shared engine:
+ # ActiveModel::Naming.route_key(Blog::Post) #=> blog_posts
#
# The route key also considers if the noun is uncountable and, in
# such cases, automatically appends _index.
@@ -281,11 +289,11 @@ module ActiveModel
# Returns string to use for params names. It differs for
# namespaced models regarding whether it's inside isolated engine.
#
- # For isolated engine:
- # ActiveModel::Naming.param_key(Blog::Post) #=> post
+ # # For isolated engine:
+ # ActiveModel::Naming.param_key(Blog::Post) #=> post
#
- # For shared engine:
- # ActiveModel::Naming.param_key(Blog::Post) #=> blog_post
+ # # For shared engine:
+ # ActiveModel::Naming.param_key(Blog::Post) #=> blog_post
def self.param_key(record_or_class)
model_name_from_record_or_class(record_or_class).param_key
end