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 = []
if (@category == nil) ||
(@category ==
@recipes << recipe

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...

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Curt Hibbs photo Better way of filtering Recipes by Category
    2005-04-07 20:18:11  Curt Hibbs | O'Reilly AuthorO'Reilly Blogger [View]

    I completely agree that the best way to do this through the proper database queries within a method in the Recipe model.

    Obviously, this article was not about best practices. :-)