namespace :localeze do desc "Update and Get new LocalezeCategories" task :import => :environment do before = LocalezeCategory.count categories = LocalezeClient.new.categories ActiveRecord::Base.transaction do categories.each do |cat| category = LocalezeCategory.where(name: cat).first_or_create! end if before < LocalezeCategory.count puts "Imported #{LocalezeCategory.count - before} categories." end end end end