如何在 ruby​​ on Rails 中获取月份名称? [英] how do I get name of the month in ruby on Rails?

查看:50
本文介绍了如何在 ruby​​ on Rails 中获取月份名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的视图中创建:

so i create in my view:

<%=date=Date.today%>

如何从日期中获取月份的名称?我试图做某事

How do i get the name of the month out of the date? I was trying to do sth like

 <%= DATE::ABBR_MONTHNAMES(date.month)%>    

但没有成功.我不断收到错误:未初始化的常量 ActionView::Base::CompiledTemplates::MONTHNAMES

But without success. I keep getting an error: uninitialized constant ActionView::Base::CompiledTemplates::MONTHNAMES

我如何初始化常量或者有没有其他方法可以从日期格式中获取名称?

How do i initialise the constant or is there any other way to get the name out of the Date format?

非常感谢您的回答!

推荐答案

Ref this

<% @date = Date.today  %>  
<%= @date.strftime("%B")%>

如果

@date >> Fri, 11 Jun 2010

然后

@date.strftime("%B") >> "June"

这篇关于如何在 ruby​​ on Rails 中获取月份名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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