Article:
 |
|
Rolling with Ruby on Rails, Part 2
|
| Subject: |
|
Better way of filtering Recipes by Category |
| Date: |
|
2005-04-07 20:06:05 |
| From: |
|
Rexbot
|
|
|
|
Instead of having all that nasty code in the html try just defining controler as follows:
def list
@category = @params['category']
@recipes_tmp = Recipe.find_all
@recipes = []
@recipes_tmp.each{|recipe|
if (@category == nil) ||
(@category == recipe.category.name)
@recipes << recipe
end
}
end
I think this better shows the elegance of having a MVC framework like Rails.
Better yet to let the DB do the work in the Recipe.find query and/or add a new method to the Recipe model for this behaviour but this gets the point across...
|
Showing messages 1 through 1 of 1.
-
Better way of filtering Recipes by Category
2005-04-07 20:18:11
Curt Hibbs | 
[View]
Obviously, this article was not about best practices. :-)