[LRUG] How does Rails decide how to parse ambiguous dates?

Mr Jaba the.jaba at gmail.com
Tue Jul 26 08:51:57 PDT 2011


I believe the type casting happens in the database adapter itself, for
example, the MySQL adapter will do it, as would the Postgres one.

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Column.html#method-c-string_to_date

You can always override the Model's accessor and do your own conversion in
there?

On 26 July 2011 16:39, John Winters <john at sinodun.org.uk> wrote:

> On 26/07/11 16:07, John Winters wrote:
> [snip]
>
>> def read_attribute_before_type_**cast(attr_name)
>>
>> @attributes[attr_name]
>> end
>>
>> Unless I've missed it somewhere, no formatting at all occurs.
>>
>
> I'm back to my earlier view that no formatting occurs in the field handling
> code, but there is some sort of conversion happening in ActiveRecord and I'm
> at a loss as to where.
>
> I have a model called an era, and it has a Date field called starts_at.
>  I've fire up the console and get the following (prompt shortened for
> clarity):
>
> > era.starts_at.class
>  => Date
> > era.attributes["starts_at"].**class
>  => Date
> > era.read_attribute_before_**type_cast("starts_at").class
>  => String
>
> Now where did that conversion occur?
>
>
> John
> ______________________________**_________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/**listinfo.cgi/chat-lrug.org<http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20110726/f1a85f3e/attachment-0003.html>


More information about the Chat mailing list