Skip to content

Instantly share code, notes, and snippets.

@just3ws
Last active December 10, 2015 07:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save just3ws/4400041 to your computer and use it in GitHub Desktop.
Save just3ws/4400041 to your computer and use it in GitHub Desktop.
Rails console helpers to put in your .irbrc that will return an array of AR model constants and an array of controller constants respectively.
def self.models
ActiveRecord::Base
.send(:subclasses)
.map { |model| model.name.constantize }
end
def self.controllers
Rails.application.routes.routes
.select { |r| r.defaults[:controller].present? }
.uniq { |r| r.defaults[:controller] }
.sort_by { |r| r.defaults[:controller] }
.map { |r| "#{r.defaults[:controller].split('/').map { |x| x.capitalize }.join("::").camelize }Controller".constantize }
end
@just3ws
Copy link
Author

just3ws commented Dec 28, 2012

I can't compare the Journey::Route instances so I have to dereference to get the controller value. I don't think this is quite as concise as my original example and requires repeating the dereference inside each block.

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