Railties – 將 Engine
黏合到 Rails
Railties 負責將所有框架黏合在一起。總體而言,它
-
處理 Rails 應用程式的啟動過程;
-
管理
rails
命令列介面; -
並提供 Rails 產生器核心。
下載
最新版的 Railties 可以使用 RubyGems 安裝
-
gem install railties
原始碼可以作為 GitHub 上 Rails 專案的一部分下載
授權
Railties 根據 MIT 授權發布
支援
API
文件位於
可以在這裡為 Ruby on Rails 專案提交錯誤報告
功能請求應在 rails-core 郵件列表中討論
- 模組 Rails::API
- 模組 Rails::Command
- 模組 Rails::Configuration
- 模組 Rails::Generators
- 模組 Rails::Info
- 模組 Rails::Initializable
- 模組 Rails::Paths
- 模組 Rails::Rack
- 模組 Rails::VERSION
- 類別 Rails::AppBuilder
- 類別 Rails::Application
- 類別 Rails::CodeStatistics
- 類別 Rails::Console
- 類別 Rails::DBConsole
- 類別 Rails::Engine
- 類別 Rails::HealthController
- 類別 Rails::PluginBuilder
- 類別 Rails::Railtie
- 類別 Rails::Server
- 類別 Rails::SourceAnnotationExtractor
- A
- B
- C
- E
- G
- P
- R
- V
屬性
[讀寫] | app_class | |
[寫入] | application | |
[讀寫] | cache | |
[讀寫] | logger |
類別公開方法
application() 連結
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 45 def application @application ||= (app_class.instance if app_class) end
autoloaders() 連結
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 126 def autoloaders application.autoloaders end
backtrace_cleaner() 連結
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 56 def backtrace_cleaner @backtrace_cleaner ||= Rails::BacktraceCleaner.new end
configuration() 連結
用於設定 Rails 環境的 Configuration
實例
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 52 def configuration application.config end
env() 連結
返回目前的 Rails 環境。
Rails.env # => "development"
Rails.env.development? # => true
Rails.env.production? # => false
Rails.env.local? # => true true for "development" and "test", false for anything else
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 75 def env @_env ||= ActiveSupport::EnvironmentInquirer.new(ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development") end
env=(environment) 連結
設定 Rails 環境。
Rails.env = "staging" # => "staging"
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 82 def env=(environment) @_env = ActiveSupport::EnvironmentInquirer.new(environment) end
error() 連結
返回目前 Rails 專案的 ActiveSupport::ErrorReporter
,如果沒有專案則返回 nil
。
Rails.error.handle(IOError) do
# ...
end
Rails.error.report(error)
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 93 def error ActiveSupport.error_reporter end
gem_version() 連結
以 Gem::Version
的形式返回目前載入的 Rails 版本。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/gem_version.rb, line 5 def self.gem_version Gem::Version.new VERSION::STRING end
groups(*groups) 連結
根據以下條件返回所有用於載入的 Rails 群組:
-
Rails 環境;
-
環境變數 RAILS_GROUPS;
-
作為參數給出的可選環境以及具有群組依賴關係的雜湊;
Rails.groups assets: [:development, :test]
# => [:default, "development", :assets] for Rails.env == "development"
# => [:default, "production"] for Rails.env == "production"
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 106 def groups(*groups) hash = groups.extract_options! env = Rails.env groups.unshift(:default, env) groups.concat ENV["RAILS_GROUPS"].to_s.split(",") groups.concat hash.map { |k, v| k if v.map(&:to_s).include?(env) } groups.compact! groups.uniq! groups end
public_path() 連結
返回目前 Rails 專案的公開資料夾的 Pathname
物件,如果沒有專案則返回 nil
Rails.public_path
# => #<Pathname:/Users/someuser/some/path/project/public>
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 122 def public_path application && Pathname.new(application.paths["public"].first) end
root() 連結
返回目前 Rails 專案的 Pathname
物件,如果沒有專案則返回 nil
Rails.root
# => #<Pathname:/Users/someuser/some/path/project>
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails.rb, line 65 def root application && application.config.root end
version() 連結
以字串形式返回目前載入的 Rails 版本。
原始碼:顯示 | 在 GitHub 上
# File railties/lib/rails/version.rb, line 7 def self.version VERSION::STRING end