No commit activity in last 3 years
No release in over 3 years
Adds *_formatted and *_formatted= methods to all rails model's date attributes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 4.2.0
 Project Readme

ActiveRecordDateFormatted

Installation

Add to your Gemfile: gem 'active_record_date_formatted'

And that's it.

Now for every active record model's date attribute, you have two additional methods, for example, if the model is Person and the attribute name is birthdate, you get following methods:

  • birthdate_formatted
  • birthdate_formatted=(formatted_date)

The formatted methods use date.formats.default format.

For example for german locale:

de:
  date:
    formats:
      default: "%d.%m.%Y" 

I18n.locale = :de
Person.first.birthdate_formatted   # => "12.04.1981"
Person.first.birthdate_formatted = "24.04.1981"
I18n.locale = :en
Person.first.birthdate_formatted   # => "1981-04-12"
Person.first.birthdate_formatted = "1981-04-24"

Now you can use the *_formatted in your views, for example when using date pickers.

Licence

This project uses MIT-LICENSE.