Skip to content

Instantly share code, notes, and snippets.

@capotej
Forked from anonymous/schemas_controller.rb
Created May 18, 2009 22:07
Show Gist options
  • Save capotej/113785 to your computer and use it in GitHub Desktop.
Save capotej/113785 to your computer and use it in GitHub Desktop.
def model_for_table(table_name)
table_name.classify.constantize
end
def index
schemas = Hash.new
ActiveRecord::Base.connection.tables.each do |table|
if table != "schema_migrations"
model = model_for_table(table)
schemas[model.table_name] << model.columns.map { |c| { :name => c.name, :type => c.type } }
end
end
respond_to do |format|
format.any { render :json => schemas }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment