Hi
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
<%= 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.new
@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”,
“purchase_date(1i)”=>“2005”}
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.new
@share.purchase_date = @params[‘sharedate’]
The date comes out as 0000-00-00
If I try
@share = Share.new(@params[‘sharedate’])
I get
1 error(s) on assignment of multiparameter attributes
And finally, if I try
@share = Share.new(@params[‘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?
Thanks
Mat.