日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Advanced Rails - Rails初始化20步

發布時間:2023/12/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Advanced Rails - Rails初始化20步 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
initializer.rb

Rails::Initialzier是用來建立Rails環境的主要類。Initializer是在config/environment.rb里面觸發的,它里面包含了下面的一個代碼塊:


Rails::Initializer.run do |config|
# (configuration)
end


Rails::Initializer.run帶進一個新的對象Rails::Configuration到這個代碼塊里。然后,run創建一個新的Rails::Initializer對象并且調用他的process方法,這個方法依次用下面的步驟來初始化Rails:

1. check_ruby_version: 保證使用的Ruby版本大于1.8.2

2. set_load_path: 添加框架的路徑(RailTies, ActionPack, ActiveSupport, ActiveRecord, Action Mailer, and Action Web Service)和應用裝載的路徑到Ruby的裝載路徑里??蚣苁窃趘endor/rails或者在RAILS_FRAMEWORK_ROOT指定的路徑裝載的。

3. require_frameworks: Loads each framework listed in the frameworks configuration option. If the framework path was not specified in RAILS_FRAMEWORK_ROOT and it does not exist in vendor/rails, Initializer will assume the frameworks are installed as RubyGems.
4.
set_autoload_paths: Sets the autoload paths based on the values of the load_ paths and load_once_paths configuration variables. These determine which paths will be searched to resolve unknown constants. The load_paths option is the same one that provided the application's load paths in step 2.
5.
load_environment: Loads and evaluates the environment-specific (development, production, or test) configuration file.
6.
initialize_encoding: Sets $KCODE to u for UTF-8 support throughout Rails.
7.
initialize_database: If ActiveRecord is being used, sets up its database configuration and connects to the database server.
8.
initialize_logger: Sets up the logger and sets the top-level constant RAILS_ DEFAULT_LOGGER to the instance. If logger is specified in the configuration, it is used. If not, a new logger is created and directed to the log_path specified. If that fails, a warning is displayed and logging is redirected to standard error.
9.
initialize_framework_logging: Sets the logger for ActiveRecord, ActionController, and Action Mailer (if they are being used) to the logger that was just set up.
10.
initialize_framework_views: Sets the view path for ActionController and Action Mailer to the value of the view_path configuration item.
11.
initialize_dependency_mechanism: Sets Dependencies.mechanism (which determines whether to use require or load to load files) based on the setting of the cache_classes configuration item.
12.
initialize_whiny_nils: If the whiny_nils configuration item is true, adds the WhinyNil extensions (that complain when trying to call id or other methods on nil) to NilClass.
13.
initialize_temporary_directories: Sets ActionController's temporary session and cache directories if they exist in the filesystem.
14.
initialize_framework_settings: Transforms the framework-specific configuration settings into method calls on the frameworks' Base classes. For example, consider the configuration option:
config.active_record.schema_format = :sql

The config.active_record object is an instance of Rails::OrderedOptions, which is basically an ordered hash (ordered to keep the configuration directives in order). During initialization, the initialize_framework_settings method transforms it into the following:
ActiveRecord::Base.schema_format = :sql

This offers the advantage that the Configuration object doesn't have to be updated every time a framework adds or changes a configuration option.
15.
add_support_load_paths: Adds load paths for support functions. This function is currently empty.
16.
load_plugins: Loads the plugins from paths in the plugin_paths configuration item (default vendor/plugins). If a plugins configuration item is specified, load those plugins respecting that load order. Plugins are loaded close to the end of the process so that they can override any already loaded component.
17.
load_observers: Instantiates ActiveRecord observers. This is done after plugins so that plugins have an opportunity to modify the observer classes.
18.
initialize_routing: Loads and processes the routes. Also sets the controller paths from the controller_paths configuration item.
19.
after_initialize: Calls any user-defined after_initialize callback. These call-backs are defined in the configuration block by config.after_initialize { … }.
20.
load_application_initializers: Loads all Rubyfiles in RAILS_ROOT/config/ initializers and any of its subdirectories. Old framework initialization that may previouslyhave been contained in config/environment.rb can now properly be broken out into separate initializers.
Now the framework is ready to receive requests.

總結

以上是生活随笔為你收集整理的Advanced Rails - Rails初始化20步的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。