On Tue, May 17, 2011 at 4:54 PM, Colin Law <[email protected]> wrote:

> On 17 May 2011 21:37, TomRossi7 <[email protected]> wrote:
> >
> >
> > On Tuesday, May 17, 2011 3:51:38 PM UTC-4, Colin Law wrote:
> >>
> >> On 17 May 2011 17:11, TomRossi7 <[email protected]> wrote:
> >> > Does anyone know how to change the default option for the Date.parse
> >> > (which ActiveRecord is using on all date fields).  I would like the
> >> > "comp" option to default to true so I don't have to account for 2-
> >> > digit dates throughout my application.
> >> >
> >> > http://corelib.rubyonrails.org/classes/Date.html#M001228
> >>
> >> Do you mean you are giving ActiveRecord a string and expecting it to
> >> parse it into a Date as it writes it to the database?
>
> I am still not sure I understand the question - is the answer to the
> above question 'yes'?
>

The answer is whenever ActiveRecord parses the string.  In Rails 3, its when
you call the setter.


>
> >> If so that is
> >> generally very dangerous.  It is much better to parse it yourself into
> >> a Date so that you can be sure you are interpreting the input
> >> correctly, and can cope with parse errors.  Then pass the Date to
> >> ActiveRecord.  Or perhaps I am misunderstanding what you are doing.
> >
> > ActiveRecord typically does a great job in typecasting, handling
> exceptions,
> > and validation so I'm not sure what you mean.  Though, this is probably a
> > different discussion altogether since my original question was just how
> to
> > tweak the options for the current parsing that ActiveRecord is already
> > doing.
>
> I was just trying to point out that there may be a better way, for
> example how do you know whether whether '10/2/05' is 2nd October or
> 10th February?  It is generally not a good idea to allow dates to be
> entered for strings.  One man's date is another man's exception.
>

Yeah, in general I agree with you.  For my application, Its working great
now, except for when a user uses a 2-digit year.


>
> Colin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to