On Jan 13, 2008 11:32 AM, Jeremy [email protected] wrote:
That makes sense except I may need just a little more hand holding
with the date_range part. In my view I have two text fields: one for
start_date and one for end_date. How do take those two dates and make
them work for the code above? In other words how do those two dates
become date_range so that they can be looped through? Thanks so much!
I’m sure there are as many ways to do it as there are members of this
I’m not far enough along in my Rails experience to know which way to
and why, but here are a couple of ideas that spring to mind.
To convert your strings to dates, you could do “1/14/2008”.to_date, or
could do Date.parse(“1/14/2008”). Note that using a four-digit year is
recommended for those two approaches; otherwise, you end up with a date
whose year is 0008. If you need to support more flexible date/time
I would recommend looking at Chronic [http://chronic.rubyforge.org/].
Once you have the two dates you can just create a range, e.g.,
date_range = (first_date…second_date)
If you haven’t already, you can try these things in IRB or the console
your Rails app.
I’d highly recommend spending as much time as you can learning Ruby. The
more I learn it, the easier working with Rails becomes. Just find
that interests you, such as ranges (of integers, dates, etc.) and play
them in IRB or the Rails console. Or, write unit tests or specs (using
[http://rspec.info]) to gain a feel for how they work. If you like, I
share a few that I wrote.