Skip to content

Instantly share code, notes, and snippets.

@StanBoyet
Created February 23, 2014 11:40
Show Gist options
  • Save StanBoyet/9170268 to your computer and use it in GitHub Desktop.
Save StanBoyet/9170268 to your computer and use it in GitHub Desktop.
Generate form, helper etc for model
require 'rubygems'
require 'active_support/core_ext'
schema = File.read('db/schema.rb')
schema.scan(/create_table "(\w+)",.*?\n(.*?)\n end/m).each do |name, ddl|
puts "rails generate scaffold #{name.classify} " +
ddl.scan(/t\.(\w+)\s+"(\w+)"/).
reject {|type,name| %w(created_at updated_at).include? name}.
map {|type,name| "#{name}:#{type}"}.join(' ')
end
#If you run this, you will get a series of commands.
#In a new directory, create a new rails application, and then run these commands (simply copying and pasting them will do).
#Grab the files you want. Delete the directory when you are done.
#from http://stackoverflow.com/a/6645304
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment