wwli
wwli

Reputation: 2681

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?

Upvotes: 1

Views: 1791

Answers (2)

CDub
CDub

Reputation: 13354

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.

Upvotes: 4

Jim Stewart
Jim Stewart

Reputation: 17323

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

Date::DAYNAMES[day.wday]

Upvotes: 1

Related Questions