[LRUG] extending Time for use throughout rails

Jonathan Leighton j at jonathanleighton.com
Fri Dec 28 10:52:28 PST 2007


You can generally put stuff like this in the lib/ directory and then
require it in environment.rb (or an initializers file these days).

However, I tend to store time formats as constants in a Format class - I
usually end up with Format::LONG_DATE, FORMAT::SHORT_DATE, etc. I guess
it doesn't hugely matter but that just feels a bit cleaner to me.

Jon

On Fri, 2007-12-28 at 18:41 +0000, Dafydd Rees wrote:
> Hello,
> 
> I want to add the concept of "geek format" (e.g. 2007-12-31) to the 
> standard time class. This is how I do it:
> 
> class Time
>    def geektime
>      strftime('%Y-%m-%d')
>    end
> end
> 
> In what file (and where) should I put this code in my rails app so
> it's accessible in all of my rails code?
> 
> The responsibilities should settle down soon and I can palm this work 
> off to an object in one part of the system but until that happens I'd 
> like to stash in in the Time class.
> 
> Cheers,
> Dafydd
-- 
Jonathan Leighton
http://jonathanleighton.com/




More information about the Chat mailing list