Chapter 1 : Rails Environments and Configuration
这一章 主要讲基本的配置一些东西,我随便的做了些笔记,加上了一些补充说明。希望对新手有帮助。或者你可以当作Tips来看:)Enjoy.
一:Enviroment Mode
Rails 有三种models:test,development,production,默认为development,你可以通过RAILS_EVN指定特定的环境
譬如
启动webrick
ruby script/server webrick -p 80 -e production
启动mongrel
mongrel_rails start -p 80 -e production
执行rake
rake db:migrate RAILS_EVN=production
二:Rails Gem Version
/config/environment.rb
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
升级rails
raile rails:update
会更新config,javascript,script,如果你只想升级单个请执行
rake rails:update:configs
rake rails:update:javascripts
rake rails:update:scripts
三:Initializer
Rails 2 新增了initializers目录,在启动的时候会加载该目录的文件。这样就不需要把一大陀的东西全塞在environment里了。
四:Default Load Paths
/vendor/rails/railties/lib/initializer.rb
def default_load_paths
paths = ["#{root_path}/test/mocks/#{environment}"]
# Add the app's controller directory
paths.concat(Dir["#{root_path}/app/controllers/"])
# Then components subdirectories.
paths.concat(Dir["#{root_path}/components/[_a-z]*"])
# Followed by the standard includes.
paths.concat %w(
app
app/models
app/controllers
app/helpers
app/services
components
config
lib
vendor
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
paths.concat builtin_directories
end
这个是rails默认加载的path,如果你想加载自己的代码到path中,可以配置在environment.rb中
/config/environment.rb
Rails::Initializer.run do |config|
#....
config.load_paths += %W(
vendor/BlueCloth-1.0.0/lib
vendor/RedCloth-3.0.4/lib
vendor/rubypants-0.2.0/lib
vendor/rubyzip-0.5.12/lib
vendor/uuidtools/lib
)
#.....
end
这样的话,你就可以把gems直接放到vendor目录下了,不需要用户去安装了。
五:Builtin Rails Info
在本机上你可以通过http://localhost:port/rails/info/properties查看,在代码中你可以通过
@properties = Rails::Info.properties
获取。
举个例子:
简单的显示如下:
<ul>
<%@properties.each_with_index do |p,index|%>
<li><%=p[0]%> : <%=p[1]%></li>
<%end%>
</ul>
六:Configuration
上面已经提过一些,这里我们再说一些
rails 默认加载如下的framework
def default_frameworks
[ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
end
你可以忽略你不需要加载的
config.frameworks -= [:action_mailer ]
七:Log-Level Override
production模式下默认使用info,其他使用debug,你可以修改如下配置
config.log_level = :debug
八:ActiveRecord Session Store
rails 2 默认是保存在客户端的,如果你想的话,可以采用其他的方式,譬如数据库存储
config.action_controller.session_store = :active_record_store
Note:
如果你还没有表,请使用
rake db:sessions:create
rake db:migrate
生成表结构
九:Observers
config.active_record.observers = :cacher, :garbage_collector
在enviroment.rb中,observers 一般配置为cache 的sweeper,或者gc等
十:Automatic Class Reloading
production 默认是cache_classes的,如果你想auto reload,请修改/config/environments/production.rb
config.cache_classes = false
development 默认为false,即当代码有变化时自动重新加载
十一:查看已加载的path
ruby script/console
Loading development environment (Rails 2.0.2)
>> $:
#....results...........
十二:Logging
rails 中默认有个全局变量RAILS_DEFAULT_LOGGER,你可以通过defined?查看是否定义
unless defined?(RAILS_DEFAULT_LOGGER) do
#create new logger ...
end
十三:Rails Log Files
清除log日志
rake log:clear
PS:同样也有tmp:clear等,用来清除tmp
十四:Log File Analysis
http://rails-analyzer.rubyforge.org/pl_analyze/
+
http://nubyonrails.com/articles/a-hodel-3000-compliant-logger-for-the-rest-of-us
分享到:
相关推荐
rails 2.0 english version
The Rails way 最新版本 The Rails way 最新版本 The Rails way 最新版本
学习ruby!
Since the API documentation is liberally licensed (just like the rest of Rails), there are some sections of the book that draw from the API documentation. But in practically all of those cases, the ...
The Rails Way
Ruby on Rails框架是Ruby的一个杀手级应用框架,可以敏捷开发Web应用,是目前为止开发效率最高的Web开发技术
The Rails™ 3 Way is a comprehensive resource that digs into the new features in Rails 3 and perhaps more importantly, the rationale behind them. —Yehuda Katz, Rails Core The Bible for Ruby on ...
The rails4 way, 英文原版
Book Details Publisher: Addison-Wesley Professional By: Obie Fernandez ISBN-10: 0321944275 ISBN-13: 978-0321944276 Year: June 8, 2014 Pages: 912 Language: English File size: 4 MB ...
The Rails™ 3 Way is the only comprehensive, authoritative guide to delivering production-quality code with Rails 3. Pioneering Rails expert Obie Fernandez and a team of leading experts illuminate ...
The rails way的pdf英文电子版,描述了rails的设计方法和例子
The Rails™ 3 Way is a comprehensive resource that digs into the new features in Rails 3 and perhaps more importantly, the rationale behind them.
The Rails 4 Way, 3rd edition.pdf
《Rails之路》 英文PDF
The Rails 5 Way(4th) 英文无水印原版pdf 第4版 pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请...
Obie Fernandez, Kevin Faustino, Vitaly Kushner - The Rails 4 Way - 2014
sunspot 学习笔记-安装以及使用,另外还有部分crontab插件的安装以及使用,适用与rails3
As a .NET developer, you’ve probably heard the buzz surrounding Ruby on Rails. It’s true: Rails enables you to create database-driven web applications with remarkable speed and ease....the Rails way.