ruby on rails - simulate timestamp in seeds.rb -
i want populate database sample data, , reason, want simulate created_at
. seeds.rb:
9.downto(1) |i| product = product.new(price: 99.99) product.created_at = i.days.ago, product.save! end
in database, result of rake db:seed
looks like,
---- 2012-03-03 16:50:30.316886000 z- 1
when need
2012-03-03 16:50:30.316886000 z- 1
how avoid these ----
symbols in result?
(db: sqlite3)
update: found when use product.created_at = i.days.ago
, in callback (before_save
) created_at
array
: [date_value, 1]
. can use
before_save { self.created_at = self.created_at[0] }
and then, value in database right (without ----
), using callbacks doesn't seem way.
the problem line:
product.created_at = i.days.ago,
you need rid of trailing comma, that's why you're ending array created_at
. fix , can rid of before_save
callback.
edit: reason getting ---
in there because whatever orm using trying serialize array , it's turning yaml.
Comments
Post a Comment