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!
Please read this post:
Rails - to_formatted_s
Create file with name: config/initializers/time_formats.rb
And you can use:
Note: You must to restart your rails server (WEBRick, FCGI, etc)
Use "time" instead of "date" in your locales file, since Rails timestamps are datetimes.
in config/locales/en.yml
in app/views/posts/show.html.haml
Use Rails I18n API.
see about I18n API
I have a file
config/initialisers/time_formats.rb
containing:You just need to restart your server to have the changes picked up.