Fetch a Rails ActiveRecord 'datetime' attribute as a DateTime object -


I have one attribute in my model that has a date / time value, and using t Is declared datetime: end_on in my migration.

When I get this value using myevent.ended_on , I get a time object. The problem is that when I try to use this feature as a single axis in a chart, it does not work properly because floatilla dates only to date or date time identifies as objects. / P>

I have thought of writing a virtual feature that will change the existing time value to datetime, but I'm careful to do this, because I've heard that the time can not handle the dates after 2040 , And I do not want to worry about later causing a "2040 bug" to worry.

Is there any way to persuade ActiveRecord to return datetime objects to this feature instead of the timeline?

You can always create a method to override the attribute, such as:

< Pre> class YourModel .... def end_on self ['end_on']. To_datetime # If you need a date object then end_date .... end

hopefully helps


Comments