views:

106

answers:

1

Hello, I am finding myself repeating typing many strftime which I defined.

Having watch Ryan Bates's railscasts ep 32/33( I think), I created a custom option for the to_s method as in Time.now.to_s, so that I can do Time.now.to_s(:sw), where :sw is my custom method, to retrieve "23 Sep 2010, 5:00PM" for example.

But the problem is, I don't know where to put #sw's definition. Should it be in a file in in the initializer folder? Or should it go in application.rb?

Thanks!

+3  A: 

I have a time_formats.rb file under the config/initialisers folder containing:

...
Time::DATE_FORMATS[:posts] = "%B %d, %Y"
Time::DATE_FORMATS[:published] = "%B %Y"
...

Someone correct me if I'm wrong but initializers are great for this as they get picked up when the application loads. I think that's the way to go. Hope this is what you are looking for.

Hugo
Okay, I thought so, too.Also because that way, you get to organize these 'helpers' in files rather than in lines in the application.rb Thanks!
Nik