Plugins - Human Attribute Override

StarAdd to favorites

HumanAttributeOverride

================

Read a tutorial for this plugin at http://weblog.redlinesoftware.com/2008/1/2/human-attribute-override-plugin-tutorial


Updates

Nov. 14, 2007

Fixed a bug where column.human_name didn’t use the new attribute name.

This should now produce the correct results:

<% for column in Company.content_columns %>

  <%= column.human_name %>

<% end %>

Aug. 18, 2007

Attributes can now be specified with symbols or strings (only strings were accepted before) ex. attr_human_name :num_employees => ‘Number of employees’, ‘unit_num’ => ‘Unit#’

Attributes can also be accessed with symbols or strings ex. Company.human_attribute_name(‘num_employees’) == ‘Number of employees’ Company.human_attribute_name(:num_employees) == ‘Number of employees’


After Rails 1.2, the method human_attribute_name will be removed, so this must be implemented as a plugin to keep the method and it’s existing uses of the method intact, while adding additional functionality described below.

This plugin allows humanized versions of attributes to be overridden with custom strings to provide a better conversion than humanize may provide.

This is useful in error reporting and possibly legacy databases where more "cryptic" field names may be used in database tables and a humanized version is not very human.

Rails uses these humanized conversions in error reporting with the error_messages_for method and in schema definitions for column names with the human_name method.

For example, a table (Company) has a field called num_employees which when humanized becomes ‘Num employees’ using the human_attribute_name method (which currently equates to a humanize method call). Ex.

Company.human_attribute_name(‘num_employees’) == ‘Num employees’

With this patch you can override this conversion…

class Company

  attr_human_name 'num_employees' => 'Number of employees'
  ...

end

Now the following is true…

Company.human_attribute_name(‘num_employees’) == ‘Number of employees’

Redline Software Inc.

http://www.redlinesoftware.com

http://svn.redlinesoftware.com/plugins/human_attribute_override

Rails' (MIT)

  • Currently 4.8/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment
Hique 3 May 2008

I did a little hack on label helper in FormBuilder. If you type

f.label :name

It will first search for human_name for that attribute. You can find it here:

http://hiquepedia.hique.org/2008/4/10/expanding-attrhumanname

Andrew 23 Jan 2008

If another plugin uses the human_name method then yes, this plugin should work with it. If another plugin uses the humanize method, then no, this plugin will not do anything since humanize is a string method.

Hique 15 Jan 2008

Does the plugin work with label helper?

Andrew 15 Nov 2007

RainChen... I have now fixed this. Thanks for reporting the issue. I didn't see your comment until today, which is why this wasn't updated earlier.

RainChen 20 Oct 2007

seems not working with : <% for column in Company.content_columns %> <p> <b><%= column.human_name %></b> </p> <% end %>

I think the issue is the code: class Column def human_name Base.humanattributename(@name) end end

Andrew 4 Oct 2007

Please check that you're not using another plugin that is breaking this one. I've been using this plugin in rails 1.2+ since it came out and have never had an issue and I've used it in multiple apps.

Please post more information on the error so I can look into any issues further.

Rhuantavan 24 Aug 2007

Could somebody please fix the issue demimismo pointed out. I am having the same problem here.

Andrew 29 Mar 2007

I wrote this plugin for use mainly with rails 1.2+. Can you show me what you changed? I've never experienced any issues so far with the plugin with any of the recent rails versions. The plugin version of full_messages is basically the same as that found in edge rails. I'll update the code asap with a little more info. Thanks.

demimismo 19 Mar 2007

Nice!

Needs update in order to work well under Rails 1.2, it crashes in Errors::full_messages because now error messages are arrays and not strings, workaround is only two lines of code :-)

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.
Recruiting software

Have a comment?