This demo app is a simple example of using transactions in ActiveRecord.
Setup the app:
- Run
bundle
to download dependencies - Run
./bin/rails db:create
to create the database - See db/seeds.rb for the code example.
- Comment either one of the entries for the
model
attribute. - Run
./bin/rails db:seed
to populate the db. This command should fail, since themodel
column was defined as not allowingnull
values according to its migration file - Check the database and ensure NO records were populated in the "guitars" table.
A simple way to check the database is running the command below
psql teste_trans_dev
select * from guitars