Skip to content

Instantly share code, notes, and snippets.

@maxwell
Created February 26, 2011 19:59
Show Gist options
  • Save maxwell/845562 to your computer and use it in GitHub Desktop.
Save maxwell/845562 to your computer and use it in GitHub Desktop.
#when i do this
def require_all_model_classes
# Rails only loads classes when they are used
# To populate our registry we require each file in app/models
models = Dir.entries(Rails.root.to_s + '/app/models/').select{|f| f =~ /^\w/}
puts models.inspect
models.each do |f|
f.sub('.rb', '').classify.constantize
end if defined?(Rails)
end
end
["aspect.rb", "aspect.rbc", "aspect_membership.rb", "aspect_membership.rbc", "comment.rb", "comment.rbc", "contact.rb", "contact.rbc", "data_point.rb", "data_point.rbc", "invitation.rb", "invitation.rbc", "jobs", "mention.rb", "mention.rbc", "mongo.rb", "mongo.rbc", "notification.rb", "notification.rbc", "notification_actor.rb", "notification_actor.rbc", "person.rb", "person.rbc", "photo.rb", "photo.rbc", "post.rb", "post.rbc", "post_visibility.rb", "post_visibility.rbc", "profile.rb", "profile.rbc", "request.rb", "request.rbc", "retraction.rb", "retraction.rbc", "service.rb", "service.rbc", "services", "statistic.rb", "statistic.rbc", "status_message.rb", "status_message.rbc", "user.rb", "user.rbc"]
@sarahmei
Copy link

Dir.entries(Rails.root.to_s + '/app/models/').select{|f| f =~ /^\w/}.each do |f|
  model = f.sub('.rb', '')
  puts model.classify
  model.classify.constantize
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment