文章引用:http://www.methods.co.nz/rails_date_kit/rails_date_kit.html#toc1

Download

http://www.methods.co.nz/rails_date_kit/rails_date_kit_1.1.0.tar.gz

step by step:
1.Setting application wide date display format

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
:default => ‘%d %b %Y’
)

2.Inputting dates with the date_field helper and calendar control

#

Put calendar.js in ./public/javascripts.
#

Put calendar.css in ./public/stylesheets.
#

Put calendar_prev.png and calendar_next.png in ./public/images.
#

Put date_helper.rb in ./app/helpers.
#

In controllers that input dates (or in the application base controller ./app/controllers/application.rb) put:

helper :date

#

Put the following lines in your page headers:

<%= stylesheet_link_tag ‘calendar’ %>

<%= javascript_include_tag ‘calendar’ %>
#

In templates with forms that input dates use the date_field helper. For example:

<%= date_field(‘person’, ‘birthday’, :value => @person.birthday) %>

Note
The date value is passed explicitly to ensure it’s formatted with the :default date format (see explanation in previous section).

3.Date Validation

Drop date_validator.rb into ./lib.

Require the validator in your models and add date validations. For example:

require_dependency ‘date_validator’

validates_dates :birthday,
:from => ’1 Jan 1930′,
:to => Date.today,
:allow_nil => true

转载请注明:韦旭红的点点滴滴 » Rails Date Kit