Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nigelramsay/stringify_date

Rails plugin to define a get and set method for dates using your own format
https://github.com/nigelramsay/stringify_date

Last synced: about 2 months ago
JSON representation

Rails plugin to define a get and set method for dates using your own format

Awesome Lists containing this project

README

        

StringifyDate
=============

Note: work in progress

Rails plugin to define a get and set method for dates using your own format.

Simple example
==============

class Person < ActiveRecord::Base
stringify_date :born_on, :format => :nz_format
end

Creates two methods called 'born_on_string' and 'born_on_string=' which will create, and parse date strings using the 'nz_format' as specified in ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS. This is often declared in your application.rb file.

Complex example
===============

class Person < ActiveRecord::Base
stringify_date :born_on, :format => :nz_format,
:stringified_name => 'birth_date', :required => true,
:required_message => 'is a mandatory field',
:invalid_message => 'should be in the format DD/MM/YYYY'
end

Error handling
==============

Creates an error message on the stringified field if:
- string does not parse (ie: invalid format supplied)
- required was true, but not supplied

TODO expand doco

Credits
=======

Ryan Bates for the original idea in his screencast "Making a plugin"
http://railscasts.com/episodes/33-making-a-plugin

Radio New Zealand who gave back to the community
http://www.radionz.co.nz

Able Technology for sponsoring further enhancements and testing
http://www.abletech.co.nz

Copyright (c) 2008 Nigel Ramsay, released under the MIT license