Setting default value for fields in Rails -
so have model request
, working perfectly. decided add "status" field, default value
def change create_table :requests |t| t.references :owner, index: true t.references :pretender, index: true t.belongs_to :book, index: true t.string :status, value: "pending", null: false t.timestamps null: false end end
but constraint not null on line:
... user.requests.build owner_id: oid, pretender_id: pid, book_id: bid ...
which working fine. if field has default value, shouldn't need define on build
method, no?
in migration file, syntax not value
, default
:
t.string :status, null: false, default: 'pending',
Comments
Post a Comment