【问题标题】:How to read ruby on rails config values from within the application controller如何从应用程序控制器中读取 ruby on rails 配置值
【发布时间】:2010-12-27 08:03:12
【问题描述】:
如果我有这样的配置文件
# config/environments/integration.rb
config.action_controller.session = {
:domain => ".example.com"
}
如何从我的应用程序控制器中获取值,例如:
# app/controller/application_controller
class ApplicationController < Mcc::CoreSupport::FrontendController
def some_method
value = xxx
end
end
【问题讨论】:
标签:
ruby-on-rails
ruby
configuration
【解决方案1】:
ActionController::Base.session_options 类方法返回会话配置选项的哈希值。
所以在你的情况下你想要ActionController::Base.session_options[:domain]
【解决方案2】:
在 Ruby on Rails 3 及更高版本中,您可以通过 Rails.application.config 访问配置
在较新的版本中,您可以改用Rails.configuration。例如:Rails.configuration.time_zone。
在official manual on configuration中查看更多信息