Created
August 11, 2011 06:29
-
-
Save ddellacosta/1139025 to your computer and use it in GitHub Desktop.
why aren't my models getting loaded in my app?
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
# in plugin_dir/lib/plugin_name.rb | |
... | |
%w{ models controllers }.each do |dir| | |
path = File.join(File.dirname(__FILE__), 'app', dir) | |
$LOAD_PATH << path | |
# it would be nice if someone updated the documentation. | |
ActiveSupport::Dependencies.autoload_paths << path | |
ActiveSupport::Dependencies.autoload_once_paths.delete(path) | |
end | |
# model (in plugin_dir/app/models/my_model.rb) | |
class MyModel < ActiveRecord::Base | |
# ... | |
def my_method | |
# does stuff | |
end | |
end | |
# if I have initializer (my_app/config/initializers/my_model.rb), it loads, and in the console I can see it | |
> MyModel | |
=> MyModel(id: integer ... ) | |
# But if not: | |
> MyModel | |
NameError: uninitialized constant MyModel | |
# What am I doing wrong? Why aren't my models from my plugin loading without the initializer? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment