Rails plugin to provide default text for NULL record fields
License
reubenmallaby/acts_as_nothing
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ActsAsNothing ============= Rails plugin to provide an easy way of setting default text for fields that may be nil. Instead of having ugly code in your views like <%= item.name.nil? ? 'My default text' : item.name %>, you just need item.name and configure the default text in the model. You can pass a prefix as a parameter if required like <%= item.name("prefix") %> The method acts_as_nothing takes a hash of field name and default text for configuration. Providing an fieldname that does not exist in the model will create a readonly method with the given name that returns the text given. Example ======= class User << ActiveRecord::Base acts_as_nothing( :name => "Anonymous" ) end View ==== (With user.name as 'Bob') <%= user.name %> Produces 'Bob' <%= user.name("by") %> Produces 'by Bob' (or user.name as nil) <%= user.name %> Produces 'Anonymous' <%= user.name('by') %> Produce 'by Anonymous' Copyright (c) 2010 Reuben Mallaby, released under the MIT license
About
Rails plugin to provide default text for NULL record fields
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published