gpt4 book ai didi

ruby-on-rails - ruby/rails 未定义方法 `DAYNAMES' 用于日期 :Class

转载 作者:太空宇宙 更新时间:2023-11-03 17:35:01 25 4
gpt4 key购买 nike

我的代码:

<% require 'date' %>
<% today = Date.today%>
<% (today..(today+7)).each{ |day| %>
<a href="#" class="btn btn-large btn-primary disabled"><%=Date::DAYNAMES(day.wday)%> </a>
<% } %>

我收到错误信息

undefined method `DAYNAMES' for Date:Class

缺少什么?

最佳答案

Date::DAYNAMES 是一个数组,而不是一个方法。来自 the docs :

DAYNAMES An array of string of full name of days of the week in English. The first is “Sunday”.

所以,你想要做的是:

<% require 'date' %>
<% today = Date.today%>
<% (today..(today+7)).each{ |day| %>
<a href="#" class="btn btn-large btn-primary disabled"><%=Date::DAYNAMES[day.wday]%> </a>
<% } %>

注意:链接中的方括号而不是圆括号。

关于ruby-on-rails - ruby/rails 未定义方法 `DAYNAMES' 用于日期 :Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19749791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com