Created
January 31, 2012 22:17
-
-
Save chrisbloom7/1713398 to your computer and use it in GitHub Desktop.
Setting up STI subclass routes programmatically
This file contains 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
if Rails.env.development? | |
# Make sure we preload the parent and children class in development | |
# since classes aren't pre-cached. Otherwise we get an error when | |
# accessing a child class before we access the parent. | |
%w[kase coaching_kase training_kase alpha_kase].each do |c| | |
require_dependency File.join("app","models","#{c}.rb") | |
end | |
end |
This file contains 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
# This will work without any prerequisites in any environment where classes are cached, | |
# but in development you will need to add an initializer that preloads the subclass files. | |
resources :kases | |
Kase.subclasses.each do |klass| | |
k = klass.name.pluralize.underscore.to_sym | |
resources k, :controller => 'kases' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, the sti preloading helped me out in rails 4