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 field.

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 datetime_select.

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 end

Please someone agree with me that it's a pretty pathetic way to do it. :slight_smile:

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 end

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