Topic: Replacing the scaffold code (?)

At the moment i've got the default scaffold methods of 'new', 'edit' etc.  But i'm not happy about some of the functionality - for example, when adding a new post to a posting list, the time that's recorded is the time when the user *started* to edit their new post, not the time they hit submit and actually posted it.

I can't work out where in the code i need to edit, though, to change what happens when the user hits submit (at which point i'd enter a datetime into the database).  I can't see a datetime being created anywhere at the moment. 

How do i go about fixing this, does anyone know?

thanks

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: Replacing the scaffold code (?)

if you talk about created_at, updated_at fields in your database table, they are created by mysql actually.

if you have your own datetime field, you can specify something like that in your model:

before_save { |r| r.datetime_attr = Time.now }

Re: Replacing the scaffold code (?)

macovsky wrote:

if you talk about created_at, updated_at fields in your database table, they are created by mysql actually.

if you have your own datetime field, you can specify something like that in your model:

before_save { |r| r.datetime_attr = Time.now }

That works perfectly, thanks!

What's the deal with the before_save method then?  Is that something that gets called automatically when saving to the DB, but is by default just a stub?

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams