Skip to content

Instantly share code, notes, and snippets.

@bts
Forked from fizx/scaffoldize.rb
Created October 15, 2008 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bts/16865 to your computer and use it in GitHub Desktop.
Save bts/16865 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# This script generates RESTful scaffolds from your pre-existing models.
# Copyright 2008 Kyle Maxwell, available under the MIT licence.
#
require "rubygems"
require "active_support"
content = File.read(File.dirname(__FILE__) + "/db/schema.rb").split("create_table")
content.shift
content.each do |section|
model = section[/"([^"]+)"/, 1].singularize
arr = section.scan(/t\.(\w+)\s+"([^"]+)"/)
values = arr.map{|type, name| "#{name}:#{type}"}.join(" ")
puts %[./script/generate scaffold #{model} #{values}]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment