@@ -171,6 +171,7 @@ def initialize(klass, namespace = nil, name = nil, locale = :en)
171
171
@klass = klass
172
172
@singular = _singularize ( @name )
173
173
@plural = ActiveSupport ::Inflector . pluralize ( @singular , locale )
174
+ @uncountable = @plural == @singular
174
175
@element = ActiveSupport ::Inflector . underscore ( ActiveSupport ::Inflector . demodulize ( @name ) )
175
176
@human = ActiveSupport ::Inflector . humanize ( @element )
176
177
@collection = ActiveSupport ::Inflector . tableize ( @name )
@@ -179,7 +180,7 @@ def initialize(klass, namespace = nil, name = nil, locale = :en)
179
180
180
181
@route_key = ( namespace ? ActiveSupport ::Inflector . pluralize ( @param_key , locale ) : @plural . dup )
181
182
@singular_route_key = ActiveSupport ::Inflector . singularize ( @route_key , locale )
182
- @route_key << "_index" if @plural == @singular
183
+ @route_key << "_index" if @uncountable
183
184
end
184
185
185
186
# Transform the model name into a more human format, using I18n. By default,
@@ -207,6 +208,10 @@ def human(options = {})
207
208
I18n . translate ( defaults . shift , **options )
208
209
end
209
210
211
+ def uncountable?
212
+ @uncountable
213
+ end
214
+
210
215
private
211
216
def _singularize ( string )
212
217
ActiveSupport ::Inflector . underscore ( string ) . tr ( "/" , "_" )
@@ -280,7 +285,7 @@ def self.singular(record_or_class)
280
285
# ActiveModel::Naming.uncountable?(Sheep) # => true
281
286
# ActiveModel::Naming.uncountable?(Post) # => false
282
287
def self . uncountable? ( record_or_class )
283
- plural ( record_or_class ) == singular ( record_or_class )
288
+ model_name_from_record_or_class ( record_or_class ) . uncountable?
284
289
end
285
290
286
291
# Returns string to use while generating route names. It differs for
0 commit comments