Ric*_*d_G 2 ruby-on-rails ruby-on-rails-4
这只是一个奇怪的刺激,但为什么我的应用程序没有在 config/application.rb 或其他任何地方包含预期的行?
require 'rails/all'
Run Code Online (Sandbox Code Playgroud)
这个应用程序是在 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
Run Code Online (Sandbox Code Playgroud)
require 'rails/all'如果这符合您的喜好,您可以,但是这些行需要运行应用程序所需的 rails 部分:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
Run Code Online (Sandbox Code Playgroud)
如果我猜测这样做的动机,可能是您不一定需要或想要应用程序中 Rails 的所有部分,因此最好明确要求您想要的部分而不是所有部分。在这种情况下,如果你愿意,require 'rails/all'你最终会得到action_view, active_job, 和rails/test_unit上面的。所需的文件可以在railties.
| 归档时间: |
|
| 查看次数: |
4417 次 |
| 最近记录: |