Topic: datetime_select

Hi everyone. This is my first post, here at

I have a quick question regarding the datetime_select helper method.

Should I be able to simply assign the resulting form value to my model as follows:

@article.original_date = params[:article][:original_date]

... or do I need to prepare the result in some way prior to assigning it to my model's attribute?

Thanks in advance!


Last edited by mGee (2006-08-16 23:43:44)

Re: datetime_select

I haven't tested it (not at a Rails computer ATM) but that should work. You can also assign all of the article parameters at once:

@article.attributes = params[:article]

Or if you want to save it too:

@article.update_attributes(params[:article]) # will call automatically

Railscasts - Free Ruby on Rails Screencasts

Re: datetime_select

Thanks, but I have to assign the attributes separately due to the fact that I need to process a couple of them prior to assignment.

What I'm finding that I have to do is the following:

    # build date
    original_date = params[:article]["original_date(1i)"]+"-"
    original_date += params[:article]["original_date(2i)"]+"-"
    original_date += params[:article]["original_date(3i)"]+" "
    original_date += params[:article]["original_date(4i)"]+":"
    original_date += params[:article]["original_date(5i)"]+":00"
    @article.original_date = original_date

Re: datetime_select

Sorry, just guessing here, but perhaps it only works on multi-parameter assignment.

You can grab the params[:article] hash then alter it however you need before setting the attributes.

article_attr = params[:article]
article_attr[:some_field] = 'some_value' # Alter whatever you need here

Railscasts - Free Ruby on Rails Screencasts