Reading date parameters


I am pretty new to this, so may be doing this all wrong…

I am having trouble setting the date field in one of my tables from the
data in a form.

I have the following markup:


<%= date_select “sharedate”, “purchase_date”, :use_month_numbers =>
false, :order => [:day, :month, :year] %>

Which generates me the usual date fields on my page.

If want to assign the date to the purchase_date column in my table:

@share =
@share.purchase_date = @params[‘sharedate’][‘purchase_date’]

The parameters on my form come back correctly as

“sharedate”=>{“purchase_date(2i)”=>“4”, “purchase_date(3i)”=>“30”,

But I get the following error when I try to update the table

Column ‘purchase_date’ cannot be null: INSERT INTO shares (cost,
quantity, purchase_date, company_id) VALUES(1.0, 1, NULL, 2)

Which indicates that the date is not being set.

If I change the code to

@share =
@share.purchase_date = @params[‘sharedate’]

The date comes out as 0000-00-00

If I try

@share =[‘sharedate’])

I get

1 error(s) on assignment of multiparameter attributes

And finally, if I try

@share =[‘sharedate’][‘purchase_date’])

I get the date as NULL again.

I can assign other parameters to columns in the table without problem,
it;s just the date.
I notice that the date parameters are in a strange format with (1i) (2i)
and (3i), so I assume this is something to do with it.

I’ve now run out of guesses - does anyone have any ideas?



Hi Mat,

One of the three ways you are doing it should work, that is this way:

@share =[‘sharedate’])

The parameters you see:

“sharedate”=>{“purchase_date(2i)”=>“4”, “purchase_date(3i)”=>“30”,

Show that the first argument to the Date constructor is the year which
is 2005, the second is the month which is 4, and the third is the month
which is 30. This is a valid date so it shouldn’t be causing a
multiparameter attributes assignment error.

Are their any other attributes in the Share model? Are any of them

A way to debug it is to actually look into where it does the
assignment and see what class it thinks it is and for what attribute
having the problem.

Sorry I couldn’t be more help,

Thanks for taking a look Frank - I’ll check it out.