Forum: Ruby on Rails Array of dates/times from time.now till nextweek

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
48b67c246071276990d6cb584b34c95a?d=identicon&s=25 Steven De ryck (-redyck-)
on 2006-04-25 15:19
Hi,

I would like to make @dates in my controller.
I tried the following:

startdate = Time.now
enddate = startdate.next_week
for enddate > startdate
   @dates << startdate
   startdate = startdate.tomorrow
end

But I get an errormessage when I check the syntax:
"warning: useless use of a variable in void context"

Anyone?

Thanks!

Steven.
58c6efb8466b9f85155fe6aa9fc37fce?d=identicon&s=25 Chris T (Guest)
on 2006-04-25 19:26
(Received via mailing list)
Still fairly newbish on rails but have you tried turning them into date
objects (to_date). Also depending on how it's being used could you
always make a range:
(startdate.to_date..enddate.to_date)

or even turn this into an array

(startdate.to_date..enddate.to_date).to_a

So i think (working this out as I go along) you could prob do

@dates = (Time.now.to_date..Time.now.next_week.to_date).to_a

which seems to work.

Hope this helps
This topic is locked and can not be replied to.