Skip to content

Instantly share code, notes, and snippets.

@brianwebb01
Created March 8, 2012 12:17
Show Gist options
  • Save brianwebb01/2000752 to your computer and use it in GitHub Desktop.
Save brianwebb01/2000752 to your computer and use it in GitHub Desktop.
Convert existing rails migration code to new script/generate command
data = <<EODATA
t.string :physical_address
t.string :physical_address2
t.string :physical_city
t.integer :physical_state_id
t.string :physical_postal_code
t.integer :physical_country_id
t.string :billing_address
t.string :billing_address2
t.string :billing_city
t.integer :billing_state_id
t.string :billing_postal_code
t.integer :billing_country_id
EODATA
results = data.scan(/\s*t.(string|boolean|integer|text|date|datetime)\s+:(\w*),*/i)
params = []
string = "script/generate scaffold MyCoolModel "
results.each do |match|
params << "#{match.last}:#{match.first}"
end
string += params.join(' ')
puts string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment