You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

21 lines
512 B

  1. module CategoriesHelper
  2. def category_collection_select
  3. cats = []
  4. Category.where(user_id: @category.user_id).each do |cat|
  5. s = cat.name
  6. cat_parent = Category.find_by(id: cat.parent_id)
  7. while cat_parent != nil do
  8. s = cat_parent.name + "/" + s
  9. cat_parent = Category.find_by(id: cat_parent.parent_id)
  10. end
  11. cat.name = s
  12. cats.push cat
  13. end
  14. collection_select(:category, :parent_id, cats.sort_by(&:name), :id, :name, include_blank: true)
  15. end
  16. end