namespace :setup do desc "Lookup for serial no" task set_serial_no: :environment do find_lookup=Lookup.where('name=?','generate_serial_no') if find_lookup.empty? lookup= Lookup.new lookup.name="generate_serial_no" lookup.max_value=0 lookup.prefix='0000' lookup.max_length=16 lookup.save end end desc "Product Type" task :set_product_type, [:name] => :environment do |t, args| find_product_type=ProductType.find_by_name(args.name) if find_product_type.nil? product_type=ProductType.new product_type.name=args.name product_type.save else puts 'Product Type is already taken!' end end desc "Product Categories" task :set_product_category, [:name,:product_type] => :environment do |t, args| find_product_type=ProductType.find_by_id(args.product_type) if !find_product_type.nil? find_product_category=ProductCategory.find_by_name(args.name) if find_product_category.nil? product_category=ProductCategory.new product_category.name=args.name product_category.product_type_id=args.product_type product_category.save end else puts 'Produt Type does not exist!' end end end