19 Aug 2010, 4:26pm
Programming Ruby on Rails: active record classify constants initialize load models rake Ruby on Rails
by bseanvt

leave a comment
Programming Ruby on Rails: active record classify constants initialize load models rake Ruby on Rails
by bseanvt
leave a comment
Load All ActiveRecord::Base Model Classes in Rails Application
Here is a simple rake task which will instantiate all of your Active Record models, provided that they are located in the RAILS_ROOT/app/models directory. Interestingly, all plugin models are instantiated by default when you run the task, for instance, if you are using the Acts As Taggable On plugin, you have access to Tag, Tagging without having to include the plugin models directory path to the task.
namespace :load_ar do
desc "load up all active record models"
task :models => :environment do
models = ActiveRecord::Base.send(:subclasses)
Dir["#{RAILS_ROOT}/app/models/*"].each do |file|
model = File.basename(file, ".*").classify
models << model unless models.include?(model)
end
end
end
If your’re in the console, you can get all the load paths for your Active Record models with the following from the API.
Rails.configuration.load_paths.each do |path| p path end
29 Jul 2009, 1:31am
Ruby on Rails video: david heinemeier hansson Ruby on Rails
by bseanvt

leave a comment
Ruby on Rails video: david heinemeier hansson Ruby on Rails
by bseanvt
leave a comment



