Skip to content

Instantly share code, notes, and snippets.

@altamic
Created July 14, 2009 23:46
Show Gist options
  • Save altamic/147328 to your computer and use it in GitHub Desktop.
Save altamic/147328 to your computer and use it in GitHub Desktop.
# produce an array of active record models for a ruby on rails app
# by Michelangelo Altamore
def _models
Dir.new(File.join(RAILS_ROOT, 'app', 'models')).select do |f|
f =~ /\.rb$/
end.map do |file|
model = file.gsub!(/\.rb$/, '').camelize
if model.constantize.ancestors.include?(ActiveRecord::Base)
model
else
nil
end
end.compact
end if ENV.include?('RAILS_ENV')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment