I'm using seeds.rb to load some dummy data into my project as I develop it.
I'd like to use a random created_at date for my records, but the created_at date is always set to Time.now on create.
#seeds.rb
Project.create :name => 'Dummy Project',
:created_at => Date.today - rand(10).days
project = Project.create(:name => 'Dummy Project')
project.created_at = (rand*10).days.ago
project.save
The created_at can't be defined during creation. It can only be changed afterwards.
This works:
p = Project.create :name => 'Dummy Project'
p.update_attribute :created_at, (rand*10).days.ago
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With