Rails set default DateTime to now
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my app I have teams and each team has a game time every week. I want the game times to be set to 'now' as a default. My table is set up like so create_table "teams", force: true do |t| t.datetime "wk1_time" end I created a migration and it looks like this: class ChangeDateTimeDefault < ActiveRecord::Migration def change change_column :teams, :wk1_time, :default => DateTime.now end edn When I run rake db:migrate I get an error. Is my syntax wrong or am I missing something else? 回答1: Yes, you are missing the type : class