Rolling with Ruby on Rails, Part 2
Subject:   "Showing recipes in a category" code
Date:   2005-03-04 15:09:19
From:   petercooper
I'm sorry, but the "Showing recipes in a category" code here is not ideal, and certainly not the best/proper way to do what you're trying to do. Consider if you have 2000 recipes in your database, and the category you are trying to view only has one recipe. You've just loaded 2000 recipes into memory to only show 1! What's more, that sort of logic should not be in the view.

Something along the lines of:

@recipes = Category.find(@params['category']?).recipes

will get all the recipes for a specific category, and you won't need any logic in the view to deal with it.

1 to 2 of 2
1 to 2 of 2