beast学习笔记——4,enviroment.rb
参考:
总:每当你启动一个进程(例如Webrick服务器)处理Rails请求的时候,第一件发生的事情就是加载config/enviroment.rb
1,
(1)代码
# Be sure to restart your server when you modify this file
(2)表示
每次修改enviroment.rb,一定要重新你启动服务
2,
(1)代码
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
#
ENV['RAILS_ENV'] ||= 'production'
(2)表示
如果你将RAILS_ENV设置为生产模式,或者修改常量RAILS_ENV,它将使Rails程序中的一切运行于
生产模式.
例如,test_helper.rb,我们可以看到它在加载环境配置之前是先把RAILS_ENV设置为测试模式的,因此它将不能正常工作.
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
但是,如果想把数据表也迁移到production中,需要使用命令:
rake db:migrate RAILS_ENV=product
3,
(1)代码
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION
(2)表示
该设置告诉environment.rb应该加载
哪个版本的Rails.(备注:一旦脚本确认了加载哪个版本的Rails,它将加载对应的Rails Gem.)
4
(1)代码
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
(2)表示
enviroment.rb之后的这一行,在加载config/boot.rb后,才真正启动了Rails
,
boot.rb启动脚本是Rails应用程序生成的一部分,但
不能修改.它能够协助你检查Rails的安装是否有问题
5
Rails::Initializer.run do |config|
# 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.
# See Rails::Configuration for more options.
#当应用被加载时,rails会自动在系统中(应该是
C:\Ruby187\lib\ruby\gems\1.8\gems
目录下)查找并require下面这些gem
#注意,
config/environments/
目录下的文件中的cofig.gem,优先级大于
enviroment.rb
中的
#如果你系统中没有,可以通过 rake gems:install来安装,或者通过gem install TheGemName一个个安装到系统中
#需要一个来自非标准站点的gem,lib名称为will_paginate(默认是mislav-will_paginate)
config.gem 'mislav-will_paginate', :lib => "will_paginate",
:source => "http://gems.github.com"
#需要最新版本的bluecloth
config.gem "bluecloth"
config.gem 'RedCloth', :lib => "redcloth",
:source => "http://code.whytheluckystiff.net"
#跳过不想使用的Rails框架
# Skip frameworks you're not going to use (only works if using vendor/rails).
# To use Rails without a database, you must remove the Active Record framework
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
#指定加载的plugins及顺序,默认是全部plugins。plugins所在目录为/vendor/plugins
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
#添加另外的加载路径#备注:%W函数的作用是对参数逐字以空格分隔并组成数组,因为使用方便,所以在Rails代码中常被使用
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/concerns )
#强制所有的环境使用同样的日志级别(缺省生产模式使用: info,其余的是: debug)
# Force all environments to use the same logger level
# (by default production uses :info, the others :debug)
# config.log_level = :debug
#验证cookie中session数据正确性的密匙
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
config.action_controller.session = {
:session_key => '_altered_beast_session',
:secret => 'f471415647be47dc513d5e345ca4e582a8f99f388e0ccd46a2cdac51e2cd27c8e8b4d7dbba379cf661d4857afaf6b1867489bbc5e16b5fb14d2c3e53df64c272'
}
#使用数据库存储session,替代默认的客户端cookie存储
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with 'rake db:sessions:create')
# config.action_controller.session_store = :active_record_store
#当创建测试数据库时,使用SQL代替Active Record,如果你的schema不能由Schema dumper完全备份时,这么做是必要的#例如,当你受限或拥有数据库特定列类型时
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
#激活需要一直运行的监听器
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
#使Active Record使用基于UTC对时区,而不是平地时间
# Make Active Record use UTC-base instead of local time
config.active_record.default_timezone = :utc
#指定rails框架使用的默认I18N语言
,
# The internationalization framework can be changed
# to have another default locale (standard is :en) or more load paths.
# All files from config/locales/*.rb,yml are added automatically.
# config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')]
# config.i18n.default_locale = :en
end