I have a requirement in my migration script that created_at column can not be null.
t.column :created_at, :datetime, :null => false
This cause the Test Fixtures loading to fail. My first attempt to remedy this problem was like this.
created_at: <%= DateTime.now %>
This did not work since the date time format is incorrect. The correct format is year-month-day hour:minute:second.
So, I changed it to
created_at: <%= DateTime.now.strftime('%y-%m-%d %H:%M:%S') %>
and it works.
I don't know if there is a better way to do this but this works for me. Since I went around looking for the solution, I decided to write it down.
Subscribe to:
Post Comments (Atom)
1 comment:
Should be able to do:
Time.now.to_s(:db)
Post a Comment