views:

10

answers:

2

Hello,

in my def create controller I'd like to include something along the lines of:

:description = > 'Uploaded on May 27, 2010"

How can I make the May 27, 2010 dynamic in the controller?

Thanks!

+1  A: 

I assume when you say you want to make May 27, 2010 then you mean you want to set the current date. For that you need to use:

:description = > "Uploaded on " + Time.now.to_s

Output will be:

"Uploaded on Fri Oct 22 21:48:49 -0700 2010"

There are many options in the Time class which you can use. This is an interesting read for timezone consideration for Rails.

zengr
well I'd like it to be contained in a string... "Uploaded on XXXXX"
AnApprentice
+2  A: 

Try this!

:description => "Uploaded on #{Date.today.strftime("%b %d,%Y")}"
krunal shah
Very nice thanks, I had to add a space after %d.!
AnApprentice