Strange bug in date_select?

Hi,

I’m having a very strange error when using the date_select.

This is de code in my view:

<%= date_select :user, :birthdate , :order => [:day, :month, :year],
:start_year => Time.now.year-120, :end_year => Time.now.year
%>

This used in the expression user.update_attributes(params[:user])

So, nothing fancy here. But when I give in a date older than 1 january
1970, I get an error:
‘1 error(s) on assignment of multiparameter attributes’, which I don’t
have with > 1970.
I checked the log, and both times the parameters are passed just fine.

Anyone has a clue?

Joram wrote:

Anyone has a clue?

i use this:
<%= date_select :user, :birth , :order => [:day, :month, :year],
:start_year => 1900, :end_year => 18.years.ago %>

and it works fine

On Thu, Mar 15, 2007 at 04:07:14AM -0700, Joram wrote :

So, nothing fancy here. But when I give in a date older than 1 january
1970, I get an error:
‘1 error(s) on assignment of multiparameter attributes’, which I don’t
have with > 1970.

AR uses Time class and not DateTime. See
http://wiki.rubyonrails.org/rails/pages/OlderQuestionsOfTheDay
(11/17/05) for more informations about this topic.

++


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Eric: I tried it, but it’s still the same for me when I enter a date <
1970

Pierre-Alexandre:
The 1970 should have made me realize it was a problem corresponnding
to the class where the time was stored.
I read your link, that’s exactly what I need, but how can I apply the
patch suggested there?

It already is, unfortunately:

create_table :users do |t|
t.column ‘username’, :string, :null => false
t.column ‘name’, :string
t.column ‘birthdate’, :datetime
end

But thanks for your input!

change the field type in your table to datetime

On 3/15/07, Joram [email protected] wrote:

AR uses Time class and not DateTime.


irfani

YM : irfani_s
http://irfani.web.id

If you use a date datatype at least in sqlite3 and sqlserver, you should
be in good shape. Just remember that any calculations must be done with
the Date class.

change_column :users, :birthdate, :date

Also, you might find this handy

User’s age in view:
<%=h ((Date.today - @user.date_of_birth)/365.25).round %>

Cheers, Simon

Hey Simon,

Sorry i didn’t answer your mail, but I wasn’t at home the past days.
I’m still having the problem at the moment, but I’ll try your approach
and let you know if it worked (I’m not at my dev pc at the moment).

I already use your tip about the age, but I was wondering why you did
365.25 where I did 365.
After some thinking it struck me that I was forgotten about the leap
years! So thank you very much for the info!

Talk to you later!

Joram

Joram,

Did you sort this one out? I’m stuck with exactly the same issue.

Hello Simon,

Thanks for your advice, it works perfectly now (tested in MySQL 5) !

Should you ever be in Belgium, we’ll have a drink :wink:

Joram