Skip to content

Commit

Permalink
Changed ActiveRecord::Base.human_name to underscore the class name be…
Browse files Browse the repository at this point in the history
…fore it humanizes it

This gives you 'Post comment' rather than 'Postcomment' by default.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#2120 state:committed]
  • Loading branch information
justinfrench authored and NZKoz committed Jun 30, 2009
1 parent 085db5e commit 7d548f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -1404,14 +1404,14 @@ def human_attribute_name(attribute_key_name, options = {})
end

# Transform the modelname into a more humane format, using I18n.
# Defaults to the basic humanize method.
# By default, it will underscore then humanize the class name (BlogPost.human_name #=> "Blog post").
# Default scope of the translation is activerecord.models
# Specify +options+ with additional translating options.
def human_name(options = {})
defaults = self_and_descendants_from_active_record.map do |klass|
:"#{klass.name.underscore}"
end
defaults << self.name.humanize
end
defaults << self.name.underscore.humanize
I18n.translate(defaults.shift, {:scope => [:activerecord, :models], :count => 1, :default => defaults}.merge(options))
end

Expand Down
8 changes: 7 additions & 1 deletion activerecord/test/cases/reflection_test.rb
Expand Up @@ -5,14 +5,20 @@
require 'models/company_in_module'
require 'models/subscriber'
require 'models/pirate'
require 'models/price_estimate'

class ReflectionTest < ActiveRecord::TestCase
fixtures :topics, :customers, :companies, :subscribers
fixtures :topics, :customers, :companies, :subscribers, :price_estimates

def setup
@first = Topic.find(1)
end

def test_human_name
assert_equal "Price estimate", PriceEstimate.human_name
assert_equal "Subscriber", Subscriber.human_name
end

def test_column_null_not_null
subscriber = Subscriber.find(:first)
assert subscriber.column_for_attribute("name").null
Expand Down

2 comments on commit 7d548f7

@justinfrench
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo!

@fesplugas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commited faster than I expected. Is it possible to have in 2.3.4?

Please sign in to comment.