ruby-on-rails – 为什么在生成模型时创建时间戳
发布时间:2020-12-16 22:23:24 所属栏目:百科 来源:网络整理
导读:rails generate model User email:string password:string 创建以下迁移脚本 class CreateUsers ActiveRecord::Migration def self.up create_table :users do |t| t.string :email t.string :password t.timestamps end end def self.down drop_table :user
rails generate model User email:string password:string 创建以下迁移脚本 class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :email t.string :password t.timestamps end end def self.down drop_table :users end end 什么是时间戳,为什么它被创建,当我不要求它创建? 解决方法
Rails自动将两列,created_at和updated_at添加到表/ migration / ActiveRecord模型中.如果你不想要它们,你可以删除它们.
自动为自己做的东西,你“没有问”是Rails擅长的:这是“配置(CoC)约定”.你可以(几乎)总是指定你想要的东西,但是一般来说,Rails将以大多数用户想要的方式来做事情. 创建和更新的时间戳通常非常有用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |