Deleting a record from database
In Ruby on Rai开发者_如何学运维ls, is it @variable.delete
or @variable.destroy
@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.
Assuming that you're using ActiveRecord, and that @variable
is an instance of an ActiveRecord::Base
subclass, you call @variable.destroy
.
精彩评论