-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
49 lines (33 loc) · 1.38 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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