Skip to content

Instantly share code, notes, and snippets.

@potatosalad
potatosalad / gist:1528977
Created December 28, 2011 18:16 — forked from Chris-Galten/gist:1528941
Making categories
step 'the following category records' do |table|
table.hashes.each do |hash|
a = AttributeSet.find_or_create_by(slug: 'myattritubetest', label: 'myattributetest', description: 'myattributeset')
if hash['parents'].present?
path = hash['parents'].split(', ')
ancestor = Category.find_or_create_by(title: path.shift, attribute_set_id: a.id)
path.each_with_index do |ancestor_title, index|
category = Category.find_or_create_by(title: ancestor_title, parent_id: ancestor.id, attribute_set_id: a.id)
ancestor = category
end
#!/usr/bin/env ruby
#
# Originally written by http://redartisan.com/tags/csv
# Added and minor changes by Gavin Laking
# Rewritten by Andrew Bennett for Ruby 1.9
#
# Usage: ruby csv_to_fixture.rb file.csv [--json]
#
# "id","name","mime_type","extensions","icon_url"
# "1","unknown","unknown/unknown","||","/images/icon/file_unknown.gif"