Deleting a record from database
26,475
Solution 1
@variable.destroy
will call all callbacks (before_destroy etc.) as well as ensure associations are respected. @variable.delete
just calls the raw database query to delete the object. You're generally much safer off using destroy
even if it's more expensive.
Solution 2
Assuming that you're using ActiveRecord, and that @variable
is an instance of an ActiveRecord::Base
subclass, you call @variable.destroy
.
Author by
Justin Meltzer
Updated on March 20, 2020Comments
-
Justin Meltzer about 4 years
In Ruby on Rails, is it
@variable.delete
or@variable.destroy