Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ProductType.all.each do |product_type|
# Check if product type has banyan category group
product_type_group = product_type.category_group
# Create banyan category group for product type if not exist
if product_type_group.nil?
product_type_group = => + " Category Group")
product_type_group.group_categorizable = product_type!
# Assign categories
product_type.product_type_categories.each do |product_type_category|
# Find or create - two steps because 3.0.4 has some problems with find_or_create_by_name
category = Banyan::Category.find_by_name(
category ||= Banyan::Category.create(:name =>
product_type_group.categories << category unless product_type_group.category_ids.include?(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.