How to set default values in Rails?

后端 未结 17 1383
醉话见心
醉话见心 2020-11-28 04:39

I\'m trying to find the best way to set default values for objects in Rails.

The best I can think of is to set the default value in the new method in

17条回答
  •  清歌不尽
    2020-11-28 04:57

    For boolean fields in Rails 3.2.6 at least, this will work in your migration.

    def change
      add_column :users, :eula_accepted, :boolean, default: false
    end
    

    Putting a 1 or 0 for a default will not work here, since it is a boolean field. It must be a true or false value.

提交回复
热议问题