Disabling eager loading effectively prevents autoloading.

  • Download Gist
Disabling eager loading effectively prevents autoloading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
#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 .
exist
create README
create Rakefile
create config.ru
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 http://rubygems.org/
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???

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.