I want to populate the database by sample data, and for some reason, I also want to simulate created_at.
This is my seeds.rb:
9.downto(1) do |i|
product = Product.new(price: 99.99)
product.created_at = i.days.ago,
product.save!
end
In the database, the result of rake db:seed looks like,
---- 2012-03-03 16:50:30.316886000 Z- 1
when I need
2012-03-03 16:50:30.316886000 Z- 1
How to avoid these ---- symbols in the result?
(db: sqlite3)
update:
I just found that when I use product.created_at = i.days.ago,
in callback (before_save) created_at is Array: [date_value, 1]. So I can use
before_save { self.created_at = self.created_at[0] }
and then, value in database will be right (without ----), but using callbacks doesn’t seem like a good way.
The problem is this line:
You need to get rid of the trailing comma, that’s why you’re ending up with an array for
created_at. Fix that and you can get rid of thebefore_savecallback.Edit: The reason you are getting the
---in there is because whatever ORM you are using is trying to serialize the Array and it’s turning it into YAML.