Module: Ramaze::Helper::Category
- Defined in:
- lib/zen/package/categories/lib/categories/helper/category.rb
Overview
Helper for the Categories package. Note that this helper requires the helper Ramaze::Helper::Message to be loaded.
Instance Method Summary (collapse)
-
- (Hash) parent_categories(category_id, category_group_id)
Method that extracts all the possible parent categories for a given category group ID.
-
- (Categories::Model::Category) validate_category(category_id, category_group_id)
Similar to validate_category_group this method checks if a category is valid or not.
-
- (Categories::Model::CategoryGroup) validate_category_group(category_group_id)
Checks if the specified category group ID results in a valid instance of Categories::Model::CategoryGroup.
Instance Method Details
- (Hash) parent_categories(category_id, category_group_id)
Method that extracts all the possible parent categories for a given category group ID.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/zen/package/categories/lib/categories/helper/category.rb', line 69 def parent_categories(category_id, category_group_id) parent_categories = {} Categories::Model::CategoryGroup[category_group_id].categories \ .each do |c| parent_categories[c.id] = c.name if c.id != category_id end parent_categories[nil] = '--' return parent_categories end |
- (Categories::Model::Category) validate_category(category_id, category_group_id)
Similar to validate_category_group this method checks if a category is valid or not. If it's valid the object is returned, otherwise an error is displayed and the user is redirected back to the overview of categories.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/zen/package/categories/lib/categories/helper/category.rb', line 45 def validate_category(category_id, category_group_id) category = ::Categories::Model::Category[category_id] if category.nil? (:error, lang('categories.errors.invalid_category')) redirect( ::Categories::Controller::Categories.r(:index, category_group_id) ) else return category end end |
- (Categories::Model::CategoryGroup) validate_category_group(category_group_id)
Checks if the specified category group ID results in a valid instance of Categories::Model::CategoryGroup. If this is the case the object is returned, otherwise the user is redirected back to the overview of all category groups and is informed about the group being invalid.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zen/package/categories/lib/categories/helper/category.rb', line 22 def validate_category_group(category_group_id) group = ::Categories::Model::CategoryGroup[category_group_id] if group.nil? (:error, lang('category_groups.errors.invalid_group')) redirect(::Categories::Controller::CategoryGroups.r(:index)) else return group end end |