简体   繁体   中英

ruby /rails undefined method `DAYNAMES' for Date:Class

my code:

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

I got error message

undefined method `DAYNAMES' for Date:Class

What is missing?

Date::DAYNAMES is an array, not a method. From the docs :

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

So, you'd want to do:

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

NOTICE : The brackets instead of the parenthesis in your link.

Date::DAYNAMES is an array, not a method. Try this:

Date::DAYNAMES[day.wday]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM