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 buildmethod, no?

in migration file, syntax not value, default:

t.string :status, null: false, default: 'pending', 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -