3

This is just a curious irritant, but why does my app not include the expected line in config/application.rb, or anywhere else?

require 'rails/all' 

This app was generated using Rails Composer in early 2014, if that makes a difference. Also, it is Rails 4.2.1.

The issue arose only because I am studying the Configuring Rails Applications and the The Rails Initialization Process guides as I have a need to modify my initialization process. Both state that the config/application.rb file is expected to contain that line, but mine does not. And, yes, the app runs just fine locally and on Heroku, so... Why?

My file is:

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Theappname
  class Application < Rails::Application

    config.generators do |g|

      # Enable Chrome Source Maps so CSS and JS can be debugged
      #g.sass_options = { :debug_info => true }

      # don't generate RSpec tests for views and helpers
      g.test_framework :rspec, fixture: true
      g.fixture_replacement :factory_girl, dir: 'spec/factories'

      g.view_specs false
      g.helper_specs false
    end

    # Rails 4 should include all helpers for controllers and views
    config.action_controller.include_all_helpers = true  

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    #config.time_zone = 'Eastern Time (US & Canada)'
    config.time_zone = 'UTC'   # Don't use local time or you won't notice time issues.

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Do not check for unavailable locales
    I18n.enforce_available_locales = false

    # not needed at 4.0
    config.assets.initialize_on_precompile = false

    # Load files in lib
    config.autoload_paths += %W(#{config.root}/lib)

    # Extend Rails classes in lib/core_ext/<classname>.rb...  See above?
    #config.autoload_paths += Dir[File.join(Rails.root, "lib", "core_ext", "*.rb")].each {|l| require l }

    # 20150711 Default Date formats
    #default_date_formats = { :default => '%d.%m.%Y' }
    default_date_formats = { :default => '%Y.%m.%d' }
    Time::DATE_FORMATS.merge!(default_date_formats)
    Date::DATE_FORMATS.merge!(default_date_formats)

    # 20150808 Adding Delayed_Job queueing for daily_report and such
    config.active_job.queue_adapter = :delayed_job

  end
end
Richard_G
  • 4,700
  • 3
  • 42
  • 78

1 Answers1

7

You can require 'rails/all' if that suits your fancy, but the parts of rails necessary to run your application are required with these lines:

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"

If I were to guess the motivation for this, it is probably that you don't necessarily need or want all of the parts of rails in your application, so better to explicitly require the ones you want instead of everything. In this case if you were to require 'rails/all' you would end up with action_view, active_job, and rails/test_unit as well as the above. The files required can be found in railties.

lobati
  • 9,284
  • 5
  • 40
  • 61
  • Well, I thought that might be the case, but I'm surprised the guides don't point this out at all even as a footnote. I did just find an answer that indirectly references it at http://stackoverflow.com/questions/2212709/remove-activerecord-in-rails-3. Thanks. – Richard_G Oct 02 '15 at 23:21
  • Yeah, I think it was a relatively recent change in rails. We've still got the old style `require 'rails/all'` in our application, but new applications have the separate requires. – lobati Oct 02 '15 at 23:34
  • 1
    From my experience, the "rails new" command writes rails/all unless a --skip-* option was used; e.g. using --skip-sprockets will write out each dependency with a comment on the sprockets line. – unremarkable Jul 16 '17 at 18:14