Last active
December 10, 2015 07:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.