ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
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...


1 to 1 of 1
  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]

1 to 1 of 1