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


AddThis Social Bookmark Button
  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 == recipe.category.name)
@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...

1 to 1 of 1
1 to 1 of 1