2015-10-02 48 views
2

这只是一个奇怪的刺激,但为什么我的应用程序不在config/application.rb或其他任何地方包含预期的行?为什么在我的config/application.rb中“require'rails/all'”没有安装/需要?

require 'rails/all' 

这个应用程序是在2014年初使用Rails Composer生成的,如果这样做有所帮助的话。另外,它是Rails 4.2.1。

这个问题的出现只是因为我正在研究Configuring Rails ApplicationsThe Rails Initialization Process指南,因为我需要修改我的初始化过程。都声明config/application.rb文件预计包含该行,但我的不。而且,是的,该应用在本地和Heroku上运行良好,所以...为什么?

我的文件是:

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 

回答

3

你可以,如果适合您的花哨,但运行应用程序所需的钢轨的部分都需要与这些线require 'rails/all'

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

如果我是为了猜测这种动机,可能是因为你不一定需要或不需要应用程序中的所有rails部分,所以更好地明确地需要你想要的而不是所有的东西。在这种情况下,如果您是require 'rails/all',那么您最终将得到action_view,active_jobrails/test_unit以及上述内容。这些文件需要can be found in railties

+0

嗯,我认为可能是这种情况,但我很惊讶,导游甚至没有指出这一点,甚至作为一个脚注。我只是在http://stackoverflow.com/questions/2212709/remove-activerecord-in-rails-3中找到间接引用它的答案。谢谢。 –

+0

是的,我认为这是一个相对较新的轨道变化。在我们的应用程序中,我们仍旧拥有旧式'require'rails/all'',但新应用程序具有单独的需求。 – lobati

+1

根据我的经验,“rails new”命令写入rails/all,除非使用--skip- *选项;例如使用--skip-sprockets将写出每个依赖关系,并在链轮行上添加注释。 – hiddenwaffle

相关问题