Error with datetime_select w/ Year <1970 on MS Windows

I am seeing something very strange that does not appear to happen on OSX. Can anyone confirm if this is a valid issue/bug?

I have created a datetime_select with the following code:

<%= datetime_select(:album, :release_date, :start_year => 1960) %>

When i select any year 1970 and above the submit form works fine and i can debug(:params) no prob… but if i submit 1969 and older, I get the following:

ActiveRecord::MultiparameterAssignmentErrors in PublicController#create

1 error(s) on assignment of multiparameter attributes

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2094:in execute_callstack_for_multiparameter_attributes' c:/ruby/lib/ruby/gems/1.8/gems/activerecord- 1.15.3/lib/active_record/base.rb:2074:in assign_multiparameter_attributes’ c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1675:in attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord- 1.15.3/lib/active_record/base.rb:1505:in initialize_without_callbacks’ c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in initialize' #{RAILS_ROOT}/app/controllers/public_controller.rb:39:in new’

#{RAILS_ROOT}/app/controllers/public_controller.rb:39:in `create’

Request

Parameters: {“commit”=>“Create”, “album”=>{“artist”=>“Jimi Hendrix”, “title”=>“Electric Lady Land”, “release_date(1i)”=>“1969”, “release_date(2i)”=>“12”, “release_date(3i)”=>“31”, “genre”=>“Rock”, “release_date(4i)”=>“00”, “release_date(5i)”=>“00”}}

Here is my version information:

About your application’s environment Ruby version 1.8.6 (i386-mswin32) RubyGems version 0.9.2

Rails version 1.2.3

Active Record version 1.15.3 Action Pack version 1.13.3 Action Web Service version 1.2.3 Action Mailer version 1.3.3 Active Support version 1.4.2 Application root C:/railz/music_library

Environment development Database adapter mysql Database schema version 0

Controller Code:

def new
    @album = Album.new

     @album.title

= ‘Electric Lady Land’ end

View Code:

    <%= start_form_tag(:action => 'create') %>
   
        Title: <%= text_field(:album, :title) %><br />

        Artist: <%= text_field(:album, :artist) %><br />
        Genre: <%= text_field(:album, :genre) %><br />
        Release Date: <%= datetime_select(:album, :release_date, :start_year => 1960) %><br />

        <br />
        <%= submit_tag("Create") %>
       
    <%= end_form_tag %>

Thank you all for your time, and my apologies if this is ridiculously newbie-ish.

If anyone knows a starting point for investigating this iw ould be happy to follow up on my own, but i'm not sure where to start. thank you

Time only works for dates that are not prior to 1970-01-01 00:00:00 UTC when stored as a number of seconds since that time (often referred to as the epoch).

Use a Date rather than a Time and you should be OK.

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

It appears that you are working through my training tutorial on Lynda.com so I should jump in to help... :slight_smile:

Some platforms don't handle dates outside the 1970-2038 range well. Rails' has to convert HTML form parameters into something that your database can store. The SQL adapter in Rails uses the Time class to do that (because it's faster) but can be told to use DateTime instead. On most systems, it's either not a problem or has been sorted out, but there are a few set ups that still cause people grief. (such as Microsoft / MS SQL)

There are official patches in the works such as: http://dev.rubyonrails.org/ticket/3430 and also do-it-yourself work arounds (a Google search for 'ActiveRecord DateTime 1970' should find them). Searches in this forum for '1970' may also yield useful tips.

My suggestion would be to input more recent dates while you continue the tutorial. It's not important for you to solve this problem in order to learn the essentials of Rails. When you actually need dates before 1970 for an application, you can try and see if it's been solved "officially", switch platforms then, or investigate the DIY solutions out there.

HTH, Kevin Skoglund