Datetime type raises error on assignment – date type don't

Hi everybody,

I have model with a datetime column named “end_date”

I use a date_select in a create view. A sample post request contains:
{“project” => {“name”=>“A project”, “end_date(3i)”=>“24”,
“end_date(1i)”=>“2011”, “end_date(2i)”=>“2”}}

I get the following error:
ActiveRecord::MultiparameterAssignmentErrors: 1 error(s) on assignment
of multiparameter attributes

Running the console:

Project.new({“name”=>“A project”, “end_date(3i)”=>“24”, “end_date(1i)”=>“2011”, “end_date(2i)”=>“2”})
ActiveRecord::MultiparameterAssignmentErrors: 1 error(s) on assignment
of multiparameter attributes
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:3061:in
execute_callstack_for_multiparameter_attributes' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:3022:inassign_multiparameter_attributes’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2749:in
attributes=' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2439:ininitialize’
from (irb):4:in `new’

Project.columns_hash[“end_date”]
=> #<ActiveRecord::ConnectionAdapters::MysqlColumn:0xb6df14a0
@type=:datetime, @precision=nil, @primary=false, @limit=nil,
@default=nil, @null=true, @name=“end_date”, @scale=nil,
@sql_type=“datetime”>

Now, I change the column type from “datetime” to “date” and it works!

Project.new({“name”=>“A project”, “end_date(3i)”=>“24”, “description”=>"", “end_date(1i)”=>“2011”, “end_date(2i)”=>“2”})
=> #<Project id: nil, name: “A project”, description: “”, created_at:
nil, updated_at: nil, creator_id: nil, updater_id: nil, end_date:
“2011-02-24”>

=> #<ActiveRecord::ConnectionAdapters::MysqlColumn:0xb6f3d4bc
@type=:date, @precision=nil, @primary=false, @limit=nil, @default=nil,
@null=true, @name=“end_date”, @scale=nil, @sql_type=“date”>

Is that a bug with datetime type or I missed something?

Cheers,

Philippe

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs