Rollback transaction after fixing in rails

Can I record after a successful save?

Allows you to specify a user model with an attribute name, email, etc.

For instance,

u=User.new
u.name="test_name"
u.email="test@email.com"
u.save

Now the record will be successfully saved in the database after that, I want to cancel my transaction (not destroy or delete). Any ideas?

+5
source share
3 answers

You can do this with transactions, see http://markdaggett.com/blog/2011/12/01/transactions-in-rails/

Example:

User.transaction do
  User.create(:username => 'Nemu')
  raise ActiveRecord::Rollback
end
+8
source

There's also a gem called PaperTrail, which we have used with great success. This can do a little more than you want.

PaperTrail . . , , .

https://github.com/airblade/paper_trail

.

+3

You can start the console in sandbox mode

$> rails c --sandbox
  • When all changes exit, rollback to the input point.
+2
source

All Articles