Hi Mat,
One of the three ways you are doing it should work, that is this way:
@share = Share.new(@params[''sharedate''])
The parameters you see:
"sharedate"=>{"purchase_date(2i)"=>"4",
"purchase_date(3i)"=>"30",
"purchase_date(1i)"=>"2005"}
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 day
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 possibly
multiparameter?
A way to debug it is to actually look into where it does the multiparameter
assignment and see what class it thinks it is and for what attribute
it''s
having the problem.
Sorry I couldn''t be more help,
Frank
On 11/30/05, Mat Diss
<mat-Bo3/rDecjVJYacaHWnZSJKxOck334EZe@public.gmane.org>
wrote:>
> 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:
>
> <label for="payment_date">Date</label><br/>
> <%= date_select "sharedate", "purchase_date",
:use_month_numbers =>
> false, :order => [:day, :month, :year] %></p>
> <p>
>
> 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.
>
>
>
>
>
>
>
>
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Frank Kim
http://betweengo.com/
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails