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

More Content by Mark Rushakoff
Previous
Jeff Ma's new company tenXer makes velocity personal
Jeff Ma's new company tenXer makes velocity personal

Congrats to our friend Jeff Ma and his latest enterprise tenXer for being written up in the New York Times...

Next
exec
exec

(Update #1 below) Say you're going to do an interactive rebase where you're going to be squashing commits ...

How do you measure digital transformation?

Take the Benchmark