- 浏览: 112843 次
- 性别:
- 来自: 火星
文章分类
最新评论
-
hexawing:
相当好的入门级文章,收藏学习了!
rake任務詳解 -
minn84:
...
2012目标 -
luopeng_sg:
请问LZ这用的是JRuby还是CRuby呢?
验证码生成插件simple_captcha -
orcl_zhang:
2套?有钱人。100本,貌似有点多。
2012目标 -
keating:
来捣乱
要有梦
1.每当你启动一个进程(例如Webrick服务器)处理Rails请求的时候,第一件发生的事情就是加载config/enviroment.rb
例如publich/dispatch.rb文件的顶部
2.
如果你将RAILS_ENV设置为生产模式,HUOZHE 或者修改常量RAILS_ENV,它将使Rails程序中的一切运行于生产模式.
例如,test_helper.rb,我们可以看到它在加载环境配置之前是先把RAILS_ENV设置为测试模式的,因此它将不能正常工作.
3.脚本enviroment.rb的首要任务是寻找Rails框架并加载它.
该设置告诉environment.rb应该加载哪个版本的Rails.(备注:一旦脚本确认了加载哪个版本的Rails,它将加载对应的Rails Gem.)
4.enviroment.rb之后的这一行,在加载config/boot.rb后,才真正启动了Rails
(备注:这个启动脚本是Rails应用程序生成的一部分,但不能修改.它能够协助你检查Rails的安装是否有问题)
5.在Ruby中,通常你想从不同的文件中加载代码到你的应用程序中时,你可以用包含一条require的语句实现
工作机制:
(1)如果类或模组并非嵌套定义,则在常量名之间插入一个下划线并加载这个名字对应的文件.
如:
(2)如果类或模组是嵌套定义,那么Rails在包含的每个模组之间插入一个下划线并从对应子目录中加载相应的文件.
如
6.在开发模式下启动任何Rails应用程序并访问http://localhost:3000/rails/info/properties.你会看到一些信息
7.config/environment.rb
8.config/environments/development.rb
test.rb
production.rb
9.DIY(如有必要可以通过copy config/enviroments目录中已存在的环境配置文件为Rails应用程序创建额外的环境配置.绝大多数自定义环境都是用来添加更多的产品配置,比如staging和QA部署)
在开发模式中使用普通的环境设定,但将数据库连接到生产数据库服务器.当你有需要快速诊断生产环境中的问题时,这将是一个急救的组合方式.
例如publich/dispatch.rb文件的顶部
require File.dirname(_FILE_) + "/../config/environment"
2.
引用
# 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'
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
如果你将RAILS_ENV设置为生产模式,HUOZHE 或者修改常量RAILS_ENV,它将使Rails程序中的一切运行于生产模式.
例如,test_helper.rb,我们可以看到它在加载环境配置之前是先把RAILS_ENV设置为测试模式的,因此它将不能正常工作.
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help'
3.脚本enviroment.rb的首要任务是寻找Rails框架并加载它.
# Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
该设置告诉environment.rb应该加载哪个版本的Rails.(备注:一旦脚本确认了加载哪个版本的Rails,它将加载对应的Rails Gem.)
4.enviroment.rb之后的这一行,在加载config/boot.rb后,才真正启动了Rails
# Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot')
(备注:这个启动脚本是Rails应用程序生成的一部分,但不能修改.它能够协助你检查Rails的安装是否有问题)
5.在Ruby中,通常你想从不同的文件中加载代码到你的应用程序中时,你可以用包含一条require的语句实现
工作机制:
(1)如果类或模组并非嵌套定义,则在常量名之间插入一个下划线并加载这个名字对应的文件.
如:
引用
AboutMy变为require/about_my/
YouKnow变为require/you_know/
YouKnow变为require/you_know/
(2)如果类或模组是嵌套定义,那么Rails在包含的每个模组之间插入一个下划线并从对应子目录中加载相应的文件.
如
引用
RpanZa::ErYaDe变为require/rpan_za/er_ya_de
6.在开发模式下启动任何Rails应用程序并访问http://localhost:3000/rails/info/properties.你会看到一些信息
7.config/environment.rb
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. #config.gem "authlogic" # 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 ] 跳过你不使用的框架(仅当使用vendor/rails 时有效) # 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 ] # Add additional load paths for your own custom dirs # config.load_paths += %W( #{RAILS_ROOT}/extras ) 为自己的默认路径添加另外的加载路径(备注:%W函数的作用是对参数逐字以空格分隔并组成数组,因为使用方便,所以在Rails代码中常被使用.) # Force all environments to use the same logger level # (by default production uses :info, the others :debug) # config.log_level = :debug 强制所有的环境使用同样的日志级别(缺省生产模式使用: info,其余的是: debug) # 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 => '_Faq_session', :secret => '59c4e510413d743345309bd5ccd7d5e957c3cc0e9b78bb00eb57e0797870884659aa44771f14b1c0124059093aca669d0f421cfcb85e40f34c79f0d9aea35581' } # config.gem "rspec", :lib => false, :version => ">= 1.2.9" # config.gem "rspec-rails", :lib => false, :version => ">= 1.2.9" #config.gem 'mislav-will_paginate', :lib => 'will_paginate', :source => 'http://gems.github.com' # 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 使用数据库代替文件系统做session(使用"rake db:sessions:create"创建Session表) # 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 当创建测试数据库时,使用SQL代替Active Record,如果你的schema不能由Schema dumper完全备份时,这么做是必要的,例如,当你受限或拥有数据库特定列类型时 # Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector 激活需要一直运行的监听器 # Make Active Record use UTC-base instead of local time # config.active_record.default_timezone = :utc 使Active Record使用基于UTC对时区,而不是平地时间 #ActiveRecord::Base.record_timestamps = false end
8.config/environments/development.rb
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.cache_classes = false 在开发环境中,应用程序的代码需要在每次请求时都重新加载.这样会延长响应时间,但是如果在代码改变不需重启网络服务器时,这种配置就会对开发有利. (备注:当config_cache_class设置为true时,Rails将使用Ruby的require语句加载类,如果此选项为false时,Rails将使用load替代.) #想要查看项目加载路径的内容,只需打开控制台并输入$: >>$: =>............. # Log error messages when you accidentally call methods on nil. config.whiny_nils = true 当碰巧调用了nil的方法时记录错误信息 # Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_view.debug_rjs = true config.action_controller.perform_caching = false config.action_view.cache_template_extensions = false 显示完整的错误报告,并使缓存无效 # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false 如果邮件未发送,不必在意.
test.rb
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true #(这里可以看到development里的事false,原因如下-->) 测试数据库是"scratch space",是专为测试集准备的,使其在测试运行时擦除和重建,不要依赖该库中的数据. # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Tell ActionMailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test 让ActionMailer 不发送实际的emails,:test目录方法在ActionMailer::Base.deliveries数组中累积发送emails
production.rb
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true 生产环境意味着完成'live'程序,请求的间隔中代码不会被重载. # Use a different logger for distributed setups # config.logger = SyslogLogger.new 为分布式安装使用不同的登录器 # Full error reports are disabled and caching is turned on config.action_controller.consider_all_requests_local = false config.action_controller.perform_caching = true config.action_view.cache_template_loading = true 打开缓存,同时令完整的错误报告失效. # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" 使stylesheets,images和javascript文件开始服务 # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false 使错误输出失效,因此错的email地址会被忽略.
9.DIY(如有必要可以通过copy config/enviroments目录中已存在的环境配置文件为Rails应用程序创建额外的环境配置.绝大多数自定义环境都是用来添加更多的产品配置,比如staging和QA部署)
在开发模式中使用普通的环境设定,但将数据库连接到生产数据库服务器.当你有需要快速诊断生产环境中的问题时,这将是一个急救的组合方式.
发表评论
-
快闪行动-->为你的项目添加标签模块
2011-04-23 16:44 1124在开始之前,还是要不厌其烦的说说,那些不必要写的你自己搞把,反 ... -
Paperclip在Windows下的那些Po事
2011-04-02 04:22 12571.Paperclip提示command is not rec ... -
FireBug实用指南
2011-03-28 00:14 1315古语有云:工欲善其事必先利其器.对于Web开发人员来说, ... -
在或不在
2011-02-13 23:58 0我在我的路上停止了脚步,为的是走一条新的路...没有人明白我的 ... -
验证码生成插件simple_captcha
2011-01-12 23:37 1855插件地址:https://github.com/eshopwo ... -
关于Mar's shoe的创意思考
2011-01-12 00:52 982在昨天我的一个伙 ... -
ruby各种小脚本(集装箱)
2010-12-01 03:32 1749有时候听歌听的入迷了,就想下载google的歌词,可是下下来总 ... -
我是rails插件控
2010-12-01 03:01 0有些问题总是有点疑惑,既然能够用插件解决,为啥要自己写呢?反正 ... -
豆瓣“我说”功能的rails简单实现
2010-11-30 23:07 011111 -
用rails开发新版的起点中文网
2010-11-30 23:06 011111 -
用rails实现简单邮件发送测试
2010-11-02 17:53 1425我的环境是ruby1.8.7, rails ... -
工作中遇到的Aajx
2010-10-30 10:22 01.ObjectRange $A($R(1,5)).join( ... -
后台订单处理提醒功能
2010-10-26 17:31 01.参考豆瓣提醒 2. 用户<%= link_to&qu ... -
工作遇到的图片问题
2010-10-26 11:09 0<% record = shirt_window %&g ... -
工作中遇到的JS
2010-10-26 10:17 01.getElementById() 方法可返回对拥有指定 I ... -
页面代码
2010-10-25 13:08 0<% record = shirt_window %&g ... -
工作中遇到的CSS
2010-10-24 20:13 01.cursor 属性规定要显示的光标的类型(形状). 引用 ... -
工作小记
2010-10-19 18:50 01.svn commit 提交要注意别把别人的代码冲走了.. ... -
問答頻道模塊開發
2010-10-12 09:22 0直接參考JE的問道頻道.... -
草稿箱的崛起...
2010-09-30 16:51 0你懂个P啊...
相关推荐
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 ...
《Rails之道》按照Rails的各个子系统进行组织编排,分别介绍了Rails的环境、初始过程、配置和日志记录,Rails的分配器、控制器、页面生成和路由,REST、资源和Rails,ActiveRecord的基础、关联、验证和高级技巧,...
rails-dev-box, 面向 Ruby on Rails 核心开发的虚拟机 用于 Ruby on Rails 核心开发的虚拟机简介注意:这个虚拟机不是为 Rails 应用程序开发而设计的,只是为。 这个项目自动设置开发环境,以便在 Ruby on Rails ...
- Camera Window >>DEMO - Cinematics >>DEMO - Content Fitter >>DEMO - Forward Focus >>DEMO - Geometry Boundaries - Limit Distance >>DEMO - Limit Speed >>DEMO - Numeric Boundaries >>DEMO - Pan ...
Obie Fernandez, Kevin Faustino, Vitaly Kushner - The Rails 4 Way - 2014
Ruby on Rails Guides v2 - Ruby on Rails 4.2.5
rails-angular-postgres-and-bootstrap-second-edition 英文原版
rails-documentation-1-2-1.zip
rails-documentation-1-2-0-rc1.chm
rails-exporter-源码.rar
rails-nginx-passenger-ubuntu, 关于如何在 Nginx 8.04服务器上启动和运行和乘客的说明 rails-nginx-passenger-ubuntu我关于用 ubuntu 。Nginx 。乘客和mysql建立 Rails的简单制作服务器的笔记。别名echo"alias ll='...
《Web开发敏捷之道:应用Rails进行敏捷Web开发(第3版)》第1版曾荣获Jolt大奖“最佳技术图书”奖。在前两版的内容架构基础上,第3版增加了对Rails 2中新特性和最佳实践的内容介绍。相比第2版中的内容,Rails 2增加了...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
rails-beginner-s-guide是Rails 指导手册,帮组学习了解rails开发
rails-documentation-2-0-2
awesome-rails-gem-zh_CN, Rails 常用 Gem 列表 - Awesome Rails Gem 中文版
Ruby on Rails 初体验--北大青鸟教师专题讲座PPT 想学Ruby的赶快下载看看。 Ruby--目前最快速开发工具
rails-ftw-v0.18-2.1.5-4.1.8.exe用于在windows环境下搭建readmine环境