在Rails 3中将时间格式规则放在哪里? [英] where to put time format rules in Rails 3?

查看:65
本文介绍了在Rails 3中将时间格式规则放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己在重复输入许多我定义的strftime.

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

观看了Ryan Bates的剧集ep 32/33(我认为),我为Time_now.to_s中的to_s方法创建了一个自定义选项,以便可以执行Time.now.to_s(:sw),其中:sw是我的自定义方法,例如,检索"23 Sep 2010,5:00 PM".

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.

但是问题是,我不知道将#sw的定义放在哪里.应该在初始化文件夹中的文件中吗?还是应该放在application.rb中?

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?

谢谢!

推荐答案

我有一个文件config/initialisers/time_formats.rb包含:

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

您只需要重新启动服务器即可获取更改.

You just need to restart your server to have the changes picked up.

这篇关于在Rails 3中将时间格式规则放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆