這只是一個奇怪的刺激,但爲什麼我的應用程序不在config/application.rb或其他任何地方包含預期的行?爲什麼在我的config/application.rb中「require'rails/all'」沒有安裝/需要?
require 'rails/all'
這個應用程序是在2014年初使用Rails Composer生成的,如果這樣做有所幫助的話。另外,它是Rails 4.2.1。
這個問題的出現只是因爲我正在研究Configuring Rails Applications和The 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
嗯,我認爲可能是這種情況,但我很驚訝,導遊甚至沒有指出這一點,甚至作爲一個腳註。我只是在http://stackoverflow.com/questions/2212709/remove-activerecord-in-rails-3中找到間接引用它的答案。謝謝。 –
是的,我認爲這是一個相對較新的軌道變化。在我們的應用程序中,我們仍舊擁有舊式'require'rails/all'',但新應用程序具有單獨的需求。 – lobati
根據我的經驗,「rails new」命令寫入rails/all,除非使用--skip- *選項;例如使用--skip-sprockets將寫出每個依賴關係,並在鏈輪行上添加註釋。 – hiddenwaffle