From e8d3191c8c41f9c4973535f404c6e5887eff78f1 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Mon, 9 Jun 2008 16:21:35 +0000 Subject: [PATCH] ActionItem252: added the display_in_menu column to categories table and made the check in the helper --- app/models/category.rb | 15 +++++++++++---- app/views/shared/categories_menu.rhtml | 2 +- db/migrate/039_add_display_in_menu_to_categories.rb | 9 +++++++++ script/anhetegua | 4 ++-- test/unit/category_test.rb | 18 ++++++++---------- 5 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 db/migrate/039_add_display_in_menu_to_categories.rb diff --git a/app/models/category.rb b/app/models/category.rb index 1c251e3..5fd5339 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -54,12 +54,19 @@ class Category < ActiveRecord::Base end def display_in_menu? - if ENV['RAILS_ENV'] == 'development' - return true + display_in_menu + end + + def children_for_menu + results = [] + pending = children.find(:all, :conditions => { :display_in_menu => true}) + while !pending.empty? + cat = pending.shift + results << cat + pending += cat.children.find(:all, :conditions => { :display_in_menu => true} ) end - # FIXME don't hardcode like this. Should be a setting of the environment, maybe - total_items >= 10 + results end end diff --git a/app/views/shared/categories_menu.rhtml b/app/views/shared/categories_menu.rhtml index a79b10c..b9c41b4 100644 --- a/app/views/shared/categories_menu.rhtml +++ b/app/views/shared/categories_menu.rhtml @@ -4,7 +4,7 @@
  • > <%= item.name %>