[LRUG] How does Rails decide how to parse ambiguous dates?
Liam McAndrew
l.mcandrew at gmail.com
Tue Jul 26 08:56:54 PDT 2011
John,
I believe the clue is to look here:
http://apidock.com/rails/ActiveRecord/AttributeMethods/read_attribute
View the source and note the 'column.type_cast' line...
http://apidock.com/rails/ActiveRecord/ConnectionAdapters/Column/type_cast
Again view the source, the case statement refers to the 'type' attribute,
which is actually an instance variable for the 'simplified_type' method...
http://apidock.com/rails/ActiveRecord/ConnectionAdapters/Column/simplified_type
And that's where the magic appears to happen!
Liam.
On Tue, Jul 26, 2011 at 4:39 PM, 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/f3351e31/attachment-0003.html>
More information about the Chat
mailing list