Skip to content

javierv/display_name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

display_name

Easily specify which method to use to display an object. It was created to work in Rails models, though it works with any Ruby class.

Install

gem install display_name

Usage

class Person < ActiveRecord::Base
  display_name :full_name
end

This will generate a method “display_name” for the record, which will return the full name. It will also override the “to_s” method, so in the view you could use:

<%= person %>

That would automatically display the full name of the person. It also helps populating selects for lists of records.

Note that the display_name can be any method, and not necessary a database column.

Copyright © 2010 Javier Martín. See LICENSE for details.

About

Specify which method to use to display an object

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages