Overriding a datetime_select's value with .update_attributes

I just can’t seem to figure this out. I think I’m just looking in the
wrong place.

On an “edit post” page, I want users to be able to either specify their
own “created_at” date/time or let it default to “now”. The way I have
it set up right now is I have two radio buttons, one with a label of
“Now” and the other with a label of “Custom”, with a datetime_select
set to the post’s created_at attribute next to the Custom choice.

When they save their changes, it updates the post object with the
.update_attributes method. This automatically aggregates the
datetime_select’s values and inserts that value in the created_at

However, I want to intercept that and have it inject Time.now if the
user has selected the Now radio button.

I have tried doing a params[:post][:created_at] = Time.now; before I do
a @post.update_attributes(params[:post]); but it doesn’t seem to change
the created_at value. It still uses whatever was in the

Any ideas what I’m doing wrong here?

Okay, well, I figured out a way around it, but it seems a pretty sick
way to do it. I’m really hoping someone else has an answer. Here’s what
I have to override the datetime_select’s value…

if params[:postCreatedAt] == “now”
params[:post][“created_at(1i)”] = Time.now.year.to_s
params[:post][“created_at(2i)”] = Time.now.month.to_s
params[:post][“created_at(3i)”] = Time.now.day.to_s
params[:post][“created_at(4i)”] = Time.now.hour.to_s
params[:post][“created_at(5i)”] = Time.now.min.to_s

Please someone agree with me that it’s a pretty pathetic way to do it.

On Tue, 2006-09-12 at 23:18 -0700, Dylan B. wrote:


Please someone agree with me that it’s a pretty pathetic way to do it.

yeah - I went through that about 3 months ago…I did post up my
solution but I ended up immediately using the ‘flextimes’ plugin which
simplified everything and gave me AM/PM (12 hour) designations as well.