Help convert code form PHP to Rails.

Time to learn more rails and ruby my friend. We're not going to write
your code for you. Have an attempt and then ask questions about that
in a succinct and clear manner.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

Ok how does it not work?

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

The value for the corresponding date range is not inserting
appropriately.
I shall give an example here,

consider :

  for 'id' as 1, date of 'when' as 2009-02-01,date of 'to'
2009-02-15,'what' as test date between days ! and 'color' as #DD5511
  for 'id' as 2, date of 'when' as 2009-02-02,date of 'to'
2009-02-14,'what' as test again and 'color' as #22AA99

for the above values in the database I'm getting output as,

20090213-
20090202test again#22AA99#22AA99-
20090214-
20090203test#DD5511#DD5511-
20090215
20090204tests#CBC2FE#CBC2FE---
20090205-
20090206-
20090207-
20090208-
20090209-
20090210-
20090211-
20090212-
20090201test date between days !#DD5511#DD5511

you can see some dates are left blank.I need the values to be filled
appropriately.

Thanks in advance.