EUROPEAN DATE TEXT FIELD

This is a small gem/plugin for when you want to use a textfield to enter a European formatted date like DD/MM/YYYY, and validate to this format.

With this gem/plugin you can enter a european formatted date into your text_field.

When a correctly formatted date is passed it will be converted to a Date object and stored in the database as a date-field.

Otherwise the wrong value will be shown in the field an the database will contain nil.

SUPPORTED FORMATS

  • DD/MM/Y
  • DD/MM/YYYY
  • D/M/Y
  • DD/M/YYYY

HOWTO

Install the plugin into your Rails 3 application like this:

rails plugin install http://github.com/fousa/european-date-text-field.git

Next you should define the columns that need time conversion in your model object:

class Person < ActiveRecord::Base
  european_date :birth_date
end

Then you have to change the name of your attributes in the form:

<%= f.text_field :european_birth_date %>

BE AWARE: You must add the european_ prefix at the beginning of your column names in order for the gem/plugin to work!

VALIDATIONS

You can also use the supplied validator like this:

validates :european_birth_date, :european_date => true

Now the birth_date will be validated according to the DD/MM/Y ,DD/MM/YYYY, D/M/Y or DD/M/YYYY formats.

Make sure you use the column name with the european_ prefix, because it's this field we want to validate and not the database column!

QUESTIONS

Just ask here on Github!