How to use created_at value as default in Rails

淺唱寂寞╮ 提交于 2020-01-07 04:28:27

问题


How can I set one of my database table to created_at as default value. I did this but didn't work, I have checked in the DB and the value of code is null.

class CreateEvents < ActiveRecord::Migration
  def change
   create_table :events do |t|
    t.string :title
    t.string :location
    t.text :description
    t.date :occurs_on
    t.string :code, :default => Event::created_at

    t.timestamps

  end
 end
end

来源:https://stackoverflow.com/questions/9087494/how-to-use-created-at-value-as-default-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!