My list of changes after moving to Rails 5:
- Place
libdir intoappbecause all code inside app is autoloaded in dev and eager loaded in prod and most importantly is autoreloaded in development so you don’t have to restart server each time you make changes. - Remove any
requirestatements pointing to your own classes insidelibbecause they all are autoloaded anyway if their file/dir naming are correct, and if you leaverequirestatements it can break autoreloading. More info here - Set
config.eager_load = truein all environments to see code loading problems eagerly in dev. - Use
Rails.application.eager_load!before playing with threads to avoid “circular dependency” errors. -
If you have any ruby/rails extensions then leave that code inside old
libdirectory and load them manually from initializer. This will ensure that extensions are loaded before your further logic that can depend on it:# config/initializers/extensions.rb Dir["#{Rails.root}/lib/ruby_ext/*.rb"].each { |file| require file } Dir["#{Rails.root}/lib/rails_ext/*.rb"].each { |file| require file }