Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Disabling eager loading effectively prevents autoloading.
#install 3.1.1rc1
joerafaniello@:~/Code/playground/rails_3_1_stable$ gem install rails --pre
Successfully installed activesupport-3.1.1.rc1
Successfully installed activemodel-3.1.1.rc1
Successfully installed actionpack-3.1.1.rc1
Successfully installed activerecord-3.1.1.rc1
Successfully installed activeresource-3.1.1.rc1
Successfully installed actionmailer-3.1.1.rc1
Successfully installed railties-3.1.1.rc1
Successfully installed rails-3.1.1.rc1
8 gems installed
joerafaniello@:~/Code/playground/rails_3_1_stable$ rails -v
Rails 3.1.1.rc1
joerafaniello@:~/Code/playground/rails_3_1_stable$ rails new .
create README
create Rakefile
create .gitignore
create Gemfile
create app
create app/assets/images/rails.png
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create app/mailers/.gitkeep
create app/models/.gitkeep
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/initializers/wrap_parameters.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create lib/assets
create lib/assets/.gitkeep
create log
create log/.gitkeep
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create script
create script/rails
create test/fixtures
create test/fixtures/.gitkeep
create test/functional
create test/functional/.gitkeep
create test/integration
create test/integration/.gitkeep
create test/unit
create test/unit/.gitkeep
create test/performance/browsing_test.rb
create test/test_helper.rb
create tmp/cache
create tmp/cache/assets
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.gitkeep
create vendor/plugins
create vendor/plugins/.gitkeep
run bundle install
Fetching source index for
Using rake (0.9.2)
Using multi_json (1.0.3)
Using activesupport (3.1.1.rc1)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.1.rc1)
Using erubis (2.7.0)
Using rack (1.3.3)
Using rack-cache (1.0.3)
Using rack-mount (0.8.3)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.0.0)
Using actionpack (3.1.1.rc1)
Using mime-types (1.16)
Using polyglot (0.3.2)
Using treetop (1.4.10)
Using mail (2.3.0)
Using actionmailer (3.1.1.rc1)
Using arel (2.2.1)
Using tzinfo (0.3.29)
Using activerecord (3.1.1.rc1)
Using activeresource (3.1.1.rc1)
Using bundler (1.0.18)
Using coffee-script-source (1.1.2)
Using execjs (1.2.9)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using rdoc (3.9.4)
Using thor (0.14.6)
Using railties (3.1.1.rc1)
Using coffee-rails (3.1.1)
Using jquery-rails (1.0.14)
Using json (1.6.1)
Using rails (3.1.1.rc1)
Using sass (3.1.7)
Using sass-rails (3.1.2)
Installing sqlite3 (1.3.4) with native extensions
Using uglifier (1.0.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
joerafaniello@:~/Code/playground/rails_3_1_stable$ rails g model user
invoke active_record
create db/migrate/20110927153927_create_users.rb
create app/models/user.rb
invoke test_unit
create test/unit/user_test.rb
create test/fixtures/users.yml
joerafaniello@:~/Code/playground/rails_3_1_stable$ rake db:migrate
== CreateUsers: migrating ====================================================
-- create_table(:users)
-> 0.0011s
== CreateUsers: migrated (0.0012s) ===========================================
# Check autoloading...
joerafaniello@:~/Code/playground/rails_3_1_stable$ rails c
Loading development environment (Rails 3.1.1.rc1)
ruby-1.8.7-p352 :001 > User
=> User(id: integer, created_at: datetime, updated_at: datetime)
# Works
ruby-1.8.7-p352 :002 > exit
# Now, disable eager loading since I don't want my production system eager loading.
# add config.eager_load_paths = [] to application.rb
joerafaniello@:~/Code/playground/rails_3_1_stable$ nano config/application.rb
# Now, autoloading of all directories in app is disabled because eager_load_paths is empty
joerafaniello@:~/Code/playground/rails_3_1_stable$ rails c
Loading development environment (Rails 3.1.1.rc1)
ruby-1.8.7-p352 :001 > User
NameError: uninitialized constant User
from (irb):1
ruby-1.8.7-p352 :002 > exit
# Now, dup the eager_load_paths and set autoload_paths to it before disabling eager_load_paths, ie,
# config.autoload_paths = config.eager_load_paths.dup
# config.eager_load_paths = []
joerafaniello@:~/Code/playground/rails_3_1_stable$ nano config/application.rb
joerafaniello@:~/Code/playground/rails_3_1_stable$ rails c
Loading development environment (Rails 3.1.1.rc1)
ruby-1.8.7-p352 :001 > User
=> User(id: integer, created_at: datetime, updated_at: datetime)
# Now it works???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment