Module: Caboose::CategoriesHelper
- Defined in:
- app/helpers/caboose/categories_helper.rb
Instance Method Summary collapse
- #category_checkboxes(top_categories, selected_ids = nil) ⇒ Object
- #category_checkboxes_helper(cat, selected_ids, str, prefix = "") ⇒ Object
- #category_list(category = root_category) ⇒ Object
- #category_list_items(category) ⇒ Object
- #category_options(category, selected_id, prefix = "") ⇒ Object
- #category_select(form_name, category = root_category, selected_id = nil) ⇒ Object
- #root_category ⇒ Object
- #top_level_categories ⇒ Object
Instance Method Details
#category_checkboxes(top_categories, selected_ids = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/helpers/caboose/categories_helper.rb', line 54 def category_checkboxes(top_categories, selected_ids = nil) str = "<ul>" top_categories.each do |cat| category_checkboxes_helper(cat, selected_ids, str) end str << "</ul>" return str end |
#category_checkboxes_helper(cat, selected_ids, str, prefix = "") ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/caboose/categories_helper.rb', line 63 def category_checkboxes_helper(cat, selected_ids, str, prefix = "") str << "<li>" if cat.children && cat.children.count > 0 str << "<input type='checkbox' id='cat_#{cat.id}' value='#{cat.id}'" str << " checked='true'" if selected_ids && selected_ids.include?(cat.id) str << "> <label for='#{cat.id}'><h3>#{cat.name}</h3></label>" else str << "<input type='checkbox' id='cat_#{cat.id}' value='#{cat.id}'" str << " checked='true'" if selected_ids && selected_ids.include?(cat.id) str << "> <label for='#{cat.id}'>#{cat.name}</label>" end cat.children.each do |cat2| str << "<ul>" category_checkboxes_helper(cat2, selected_ids, str, "#{prefix} ") str << "</ul>" end str << "</li>" end |
#category_list(category = root_category) ⇒ Object
11 12 13 |
# File 'app/helpers/caboose/categories_helper.rb', line 11 def category_list(category=root_category) content_tag :ul, category_list_items(category) end |
#category_list_items(category) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/caboose/categories_helper.rb', line 15 def category_list_items(category) # Link to category link = link_to(category.name, "/admin/categories/#{category.id}") # Recursively find category children children = content_tag :ul, category.children.collect { |child| category_list_items(child) }.join.to_s.html_safe if category.children.any? # Return the list item content_tag :li, link.concat(children) end |
#category_options(category, selected_id, prefix = "") ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/caboose/categories_helper.rb', line 39 def (category, selected_id, prefix="") # Array to hold options = Array.new # Recusively tterate over all child categories category.children.collect do |child| << ["#{prefix} - #{child.name}", child.id] .concat (child, selected_id, "#{prefix} -") end # Return the options array return end |
#category_select(form_name, category = root_category, selected_id = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/caboose/categories_helper.rb', line 27 def category_select(form_name, category=root_category, selected_id=nil) # Collect all recursive options from specified category down = (category, selected_id) # Prepend the root category .unshift([category.name, category.id]) # Create select tag select_tag form_name, () end |