I thought them same thing and fixed it. I think what I did was replace "@recipes = Recipe.find_all" with some thing like "@recipes = Recipe.find(:all, :conditions => ["id = ?", params[''id'']]) So instead of populating @recipes with all records it only populates with records which match the category passed in params. You would then take the if out the view so it displayed all records in @recipes. I can''t remember excatly what is passed to the list method, is it a @category object or just the category id? Hope that helps, sorry I cant be clearer. Kris. Tobias Jordans wrote:>Hi! > >In the great Oreally Cookbook-Tutorial categories are listed like this: > ># recipe_controller.rb > def list > @recipes = Recipe.find_all > @category = @params[''category''] > end > ># recipe/list.rhtml > <% @recipes.each do |recipe| %> > <% if (@category == nil) || (@category == recipe.category.name)%> > <htmlcode /> > <% end %> > <% end %> > > >So every time all the recipes are given to the template that has to decide >if to display them or not. > > >Isn''t this pretty bad for the performance if more recipes have to be >handeled? > >So I am trying to just select the recipes that are in question. >And I dont get it right =(. > > def list > @recipes = Recipe.find_all > > if @params[:category] > @name_to_id = Category.find_by_name(@params[:tenttype]) > @recipes_selected = Recipe.find_by_category_id(@name_to_id.id) > # ^-- does not work =( > @recipes_selected = Recipe.find(:all, :conditions => >"Recipe.category_id = @name_to_id.id") > # ^-- doesnt work eather > else > @recipes_selected = Recipe.find_all > end > end > > >What is wrong here? >The condition doesnt work an the find_by doesnt eather... > > >Thanks > >~Tobias > > > >-- Interkonect Services UK Ltd. Boundary House Main Street Hoveringham Nottingham NG147 JR web: interkonect.com tel: 0115 9663696 fax: 0115 9663696
Hi! In the great Oreally Cookbook-Tutorial categories are listed like this: # recipe_controller.rb def list @recipes = Recipe.find_all @category = @params[''category''] end # recipe/list.rhtml <% @recipes.each do |recipe| %> <% if (@category == nil) || (@category == recipe.category.name)%> <htmlcode /> <% end %> <% end %> So every time all the recipes are given to the template that has to decide if to display them or not. Isn''t this pretty bad for the performance if more recipes have to be handeled? So I am trying to just select the recipes that are in question. And I dont get it right =(. def list @recipes = Recipe.find_all if @params[:category] @name_to_id = Category.find_by_name(@params[:tenttype]) @recipes_selected = Recipe.find_by_category_id(@name_to_id.id) # ^-- does not work =( @recipes_selected = Recipe.find(:all, :conditions => "Recipe.category_id = @name_to_id.id") # ^-- doesnt work eather else @recipes_selected = Recipe.find_all end end What is wrong here? The condition doesnt work an the find_by doesnt eather... Thanks ~Tobias -- Weblog: flyingsparks.wwwfiles.de
Hi Kris! Kris Leech worte:> I thought them same thing and fixed it. > > I think what I did was replace "@recipes = Recipe.find_all" with some > thing like "@recipes = Recipe.find(:all, :conditions => ["id = ?", > params[''id'']])(...) Thanks that helped me finding the right code :). I started a revision of the tutorial at the railswiki wiki.rubyonrails.com/rails/pages/onlampTutorialRevised Maybe someone wants to add something. ~Tobias> Tobias Jordans wrote:> >In the great Oreally Cookbook-Tutorial categories are listed > like this: > ># recipe_controller.rb > > def list > > @recipes = Recipe.find_all > > @category = @params[''category''] > > end > > > ># recipe/list.rhtml > > <% @recipes.each do |recipe| %> > > <% if (@category == nil) || (@category == recipe.category.name)%> > > <htmlcode /> > > <% end %> > > <% end %> > >(...)