Article:
  Cookin' with Ruby on Rails - More Designing for Testability
Subject:   practice efficient code
Date:   2007-08-07 04:56:03
From:   IbrahimAhmed
Is there a real need to use a find(:all), an each loop, then invoke a destroy method for each instance just to delete all records in a table, I know it is just a test code but people are getting used easily to this inefficient code.


I notice that you repeated the same technique more than once in your tutorial.


Wouldn't be more efficient to use...



Recipe.delete_all


instead of...



def setup
recipes = Recipe.find(:all)
recipes.each do |this_recipe|
this_recipe.destroy
end
end