这只是一个令人好奇的刺激因素,但是为什么我的应用程序未在config / application.rb或其他任何地方包含预期的行?
require 'rails/all'
如果有帮助,此应用是在2014年初使用Rails Composer生成的。此外,它是Rails 4.2.1。
之所以出现此问题,是因为我正在研究《配置Rails应用程序》和《 Rails初始化过程》指南,因为我需要修改自己的初始化过程。两者都指出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
您可以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_job
和rails/test_unit
以及上面。所需文件可在中找到railties
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句