We're finally getting destroy! in Rails 4

June 8, 2012 Mark Rushakoff

Unlike create!, save!, and friends, the destroy! method didn’t exist in Rails 3.
It took me a while to get used to destroy instead of destroy! from the Rails console and from test code, but Rails 4 will provide destroy!, which is different from destroy in the following ways:

  • Instead of returning false on failure, it will raise ActiveRecord::RecordNotDestroyed
  • If you have a before_destroy callback that returns false, it will still raise ActiveRecord::RecordNotDestroyed

There’s going to be a lot less cycles of “write a test that calls destroy!, see a NoMethodError, change destroy! to destroy, and re-run the test” once Rails 4 is released. I know I’ve lost a few minutes of my life doing that :)

About the Author

Biography

Previous
Introduction to Dart
Introduction to Dart

Dart is more than a new structured web programming language. Google’s Dart Developer Advocate, Seth Ladd, t...

Next
git reset -p
git reset -p

I've been using git reset -p a lot recently and I think it makes sense to clarify what it is that it does b...