Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6989 (closed enhancement: fixed)

Opened 2 years ago

Last modified 3 months ago

[PATCH] specify rules, strings for humanize inflections

Reported by: dcmanges Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveSupport Version: edge
Severity: normal Keywords: inflections humanize
Cc:

Description

The humanized attribute names for ActiveRecord errors are not always user friendly. ActiveRecord does not provide a means for overwriting the attribute name used in error messages. For that usage, as well as general purpose:

Inflector.inflections do |inflect|
  inflect.human /_cnt$/i, '\1_count'
  inflect.human "legacy_col_person_name", "Name"
  inflect.human "strt_dt" => "Start date",
                "upd_dt"  => "Updated date"
end

"the_cnt".humanize #=> "The count"
"upd_dt".humanize  #=> "Updated date"

Attachments

humanize_inflections.diff (3.5 kB) - added by dcmanges on 01/11/07 05:44:06.
humanize_inflections.2.diff (4.2 kB) - added by dcmanges on 01/11/07 22:36:12.
humanize_inflections_rev3.diff (4.1 kB) - added by josh on 02/24/07 18:02:14.
Tidied up patch against r6216.

Change History

01/11/07 05:44:06 changed by dcmanges

  • attachment humanize_inflections.diff added.

01/11/07 05:46:48 changed by dcmanges

I am aware of ActiveRecord::Base.human_attribute_name, but it's deprecated:

# Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example:
#   Person.human_attribute_name("first_name") # => "First name"
# Deprecated in favor of just calling "first_name".humanize
def human_attribute_name(attribute_key_name) #:nodoc:
  attribute_key_name.humanize
end

01/11/07 22:36:12 changed by dcmanges

  • attachment humanize_inflections.2.diff added.

01/11/07 22:36:53 changed by dcmanges

  • version set to edge.

Use humanize_inflections.2.diff - I forgot to update the clear method in the first patch.

02/24/07 18:02:14 changed by josh

  • attachment humanize_inflections_rev3.diff added.

Tidied up patch against r6216.

02/24/07 18:02:26 changed by josh

  • keywords changed from inflections humanize to inflections humanize verified.

07/21/07 23:03:59 changed by mpalmer

  • status changed from new to closed.
  • resolution set to wontfix.

#7199 says that inflections changes aren't going in.

07/21/07 23:22:20 changed by hasmanyjosh

Additions of particular inflection rules are not being accepted, however other changes to the Inflector (especially bugfixes) are still fair game. Feel free to re-open this ticket if there is still interest.

07/22/07 20:40:52 changed by kampers

  • status changed from closed to reopened.
  • resolution deleted.

Hold on a sec. I think this is a fair-game improvement to the inflector--and certainly not just a change to the inflection rules.

This is needed because DHH deprecated AR::Base::human_attribute_name, leaving us with no hook to change the way the attribute names get humanized -- see #8760 for a small related patch I wrote.

07/22/07 22:01:15 changed by mpalmer

  • keywords changed from inflections humanize verified to inflections humanize.

06/27/08 12:55:44 changed by dadark

Because I liked the idea a lot, have put together a very hackish plugin (http://github.com/odadata/humanize_inflections/tree/master) that monkey-patches the functionality before it goes into Rails trunk (Hope it will do soon!).

Thanks for the code, dcmanges.

07/02/08 12:47:02 changed by dadark

  • status changed from reopened to closed.
  • resolution set to fixed.

fyi, especially dcmanges: This feature has made it into edge rails now, cf. http://rails.lighthouseapp.com/projects/8994/tickets/535-humanize-inflections.

Big thanks for the idea!