views:

19

answers:

2

I have a datetime field called time in my MotionRecord model. I try to set it using this command:

MotionRecord.create({:time=> "2010-10-15 15:10:24", :chart_id=>1})

Oddly enough this results in the following input:

<MotionRecord id: 1, time: nil, chart_id: 1>

I'm not sure what I am doing wrong.

Edit: This is my model.

class MotionRecord < ActiveRecord::Base
  belongs_to :chart
  belongs_to :activity

  attr_accessor :time
end

and my schema

create_table :motion_records do |t|
  t.datetime :time
  t.integer :chart_id
  t.integer :activity_id

  t.timestamps
end
+1  A: 

This is related to your other question. Use attr_accessible :time and not attr_accessor. See http://stackoverflow.com/questions/3944288/warning-cant-mass-assign-protected-attributes

rspeicher
A: 

Or you can just set it after the create using update_attribute(:field, "value")

smcdrc
i'm doing that in the seed file. :-)
picardo